×ðÁú¿­Ê±¹ÙÍøµÇ¼

ThinkPHP 5.0 ÖÐÔõÑù¾ÙÐÐÐÞ¸Ä

thinkphp 5.0 ÊÇÒ»¿î»ùÓÚ php µÄÇáÁ¿¼¶ mvc ¿ò¼Ü¡£ËüµÄÒ×ÓÃÐÔ¡¢ÎÞаÐÔ¡¢¸ßЧÂÊʹµÃËü³ÉΪÁË¿ª·¢ÕßµÄÊ×Ñ¡¡£È»¶øËæ×ÅÏîÄ¿µÄÉîÈ뿪·¢ £¬ÎÒÃÇ¿ÉÄÜ»áÐèÒª¶Ô¿ò¼Ü¾ÙÐÐÐÞ¸ÄÒÔ˳Ӧ×Ô¼ºµÄÓªÒµÐèÇó¡£±¾ÎĽ«ÏÈÈÝÔÚ thinkphp 5.0 ÖÐÔõÑù¾ÙÐÐÐ޸ġ£

Ò»¡¢Ã÷È·´úÂë½á¹¹

ÔÚ¾ÙÐÐÐÞ¸ÄÇ° £¬ÎÒÃÇÐèÒªÏàʶ¿ò¼ÜµÄ´úÂë½á¹¹¡£Ö÷ÒªµÄ´úÂë½á¹¹ÊÇ£º

application£ºÓ¦ÓÃĿ¼ £¬Ó¦ÓõÄËùÓдúÂ붼·ÅÔÚ´ËĿ¼Ï¡£

thinkphp£ºThinkPHP ¿ò¼Ü½¹µã´úÂëĿ¼¡£

public£º¹«¹²¸ùĿ¼ £¬Í¨³£°²ÅÅ index.php ºÍ¾²Ì¬×ÊÔ´Îļþ¡£

vendor£ºComposer ÒÀÀµ¿âĿ¼¡£

¶þ¡¢Ð޸Ľ¹µãÀà¿â

Ð޸ķÓÉÀà

ThinkPHP 5.0 ÖзÓÉÀàλÓÚ thinkphp/library/think/Route.php¡£

ÓÐʱ¼ä £¬ÎÒÃÇÐèҪƾ֤Óû§µÄÇëÇó URL ×öһЩÌØÊâ´¦Àí £¬ÀýÈçÔöÌíһЩ²ÎÊý¡¢¸Ä±ä·µ»ØÖµÀàÐ͵È¡£Õâʱ¼äÎÒÃǾÍÐèÒªÐ޸ķÓÉÀà¡£Ê×ÏÈÐèÒªÔÚ application Ŀ¼Ï½¨ÉèÒ»¸ö route.php Îļþ £¬È»ºóÖØд Route ÀàµÄÒªÁì¡£ÀýÈç £¬ÎÒÃÇÏëҪƾ֤Óû§ÇëÇó URL ÔÚ·µ»ØÖµÖÐÔöÌíÒ»¸ö data ²ÎÊý £¬¿ÉÒÔ½« Route ÀàÖÐµÄ return $result; ¸ÄΪ return [‘data’ => $result];¡£Í¬Ê±ÔÚ route.php ÖÐÒýÈëÔ­À´µÄ·ÓÉÎļþ²¢ÐÞ¸Ä Route Àà¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±  £»

Ð޸ĿØÖÆÆ÷Àà

ThinkPHP 5.0 ÖÐĬÈϵĿØÖÆÆ÷ÀàλÓÚ thinkphp/library/think/Controller.php¡£

ÓÐʱ¼ä £¬ÎÒÃÇ×Ô½ç˵µÄ¿ØÖÆÆ÷ÐèҪһЩȫ¾ÖµÄ²ÎÊý»òÕßÒªÁì £¬ÀýÈçȨÏÞÑéÖ¤¡¢È«¾Ö±äÁ¿µÈ¡£´Ëʱ £¬ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷ÀàÖнç˵һ¸ö $options ÊôÐÔ £¬À´´æ´¢ÕâЩ²ÎÊý»òÕßÒªÁì¡£½Ó×Å £¬ÔÚ×Ô½ç˵µÄ¿ØÖÆÆ÷ÖÐÖØд¿ØÖÆÆ÷ÀàµÄ __construct ÒªÁì £¬²¢¼ÌÐø $options ÊôÐÔ¡£ÀýÈç £¬ÎÒÃÇÏëÒªÔÚËùÓпØÖÆÆ÷Öж¼×¢ÈëÒ»¸ö $user ±äÁ¿ £¬¿ÉÒÔ½«ÒÔÏ´úÂë¼ÓÈëµ½¿ØÖÆÆ÷ÀàÖУº

public $options;

public function __construct()
{
    $this->options = ['user' => 'test'];
    parent::__construct();
}

µÇ¼ºó¸´ÖÆ

È»ºóÔÚÏìÓ¦µÄ¿ØÖÆÆ÷ÖÐʹÓà $this->options[‘user’] ¾Í¿ÉÒÔ»ñµÃ×¢ÈëµÄ $user ±äÁ¿¡£

ÐÞ¸ÄÄ£×ÓÀà

ThinkPHP 5.0 ÖÐĬÈϵÄÄ£×ÓÀàλÓÚ thinkphp/library/think/Model.php¡£

ÓÐʱ¼ä £¬ÎÒÃÇÐèÒª¸ü¸ÄÄ£×ÓÀàµÄĬÈÏÒªÁìÒÔ˳Ӧ×Ô¼ºµÄÓªÒµÐèÇó¡£ÀýÈç £¬ÎÒÃÇÏ£ÍûËùÓеÄÅÌÎʲÙ×÷¶¼°üÀ¨Èíɾ³ý×ֶΠ£¬¿ÉÒÔÔÚÄ£×ÓÀàÖнç˵³õʼ»¯ÒªÁì £¬È»ºóŲÓÃĬÈϵÄÅÌÎÊÒªÁìʱ¾ÙÐиÄд¡£ÀýÈ磺

class MyModel extends Model
{
    protected function initialize()
    {
        parent::initialize();
        $this->where(['is_deleted' => 0])->scope('soft_delete', function($query){ 
            $query->where(['is_deleted' => 0]);
        });
    }

    public function find($dataOrWhere = null)
    {
        return $this->softDelete()->where($dataOrWhere)->find();
    }

    public function select($dataOrWhere = null)
    {
        return $this->softDelete()->where($dataOrWhere)->select();
    }
}

µÇ¼ºó¸´ÖÆ

ÕâÑù £¬ÎÒÃÇͨ¹ýÏòÅÌÎÊÌõ¼þÌí¼Ó soft_delete À´ÊµÏÖÈíɾ³ý¹ýÂË¡£

Èý¡¢ÐÞ¸ÄÉèÖÃÎļþ

ThinkPHP 5.0 µÄÉèÖÃÎļþλÓÚ application/config.php¡£

ÎÒÃÇ¿ÉÒÔÔÚÕâ¸öÉèÖÃÎļþÖÐÐ޸Ŀò¼ÜµÄĬÈÏÉèÖà £¬ÀýÈç·ÓɺÍÊý¾Ý¿â¡£ÀýÈç £¬ÈôÊÇÎÒÃÇÏ£Íû¸ü¸Ä ThinkPHP 5.0 ·ÓɵÄĬÈϲÎÊý £¬¿ÉÒÔ½«ÉèÖÃÎļþÖеÄĬÈϲÎÊýÐÞ¸ÄΪ£º

'route' => [
    'default_route_pattern' => '[\w\-\_]+',
    // Ä¬ÈϵÄ·ÓɲÎÊýÍÑÀë·û
    'default_route_depr'    => '/',
    // ÊÇ·ñ¿ªÆô·ÓÉÑÓ³ÙÆÊÎö
    'url_route_lazy'        => true,
    // ÊÇ·ñÇ¿ÖÆʹÓ÷ÓÉ
    'url_route_must'        => true,
    // ÊÇ·ñÆôÓ÷ÓÉ»º´æ
    'route_check_cache'     => true,
],

µÇ¼ºó¸´ÖÆ

ͬÑùµÄ £¬ÎÒÃÇÒ²¿ÉÒÔÔÚÉèÖÃÎļþÖÐÌí¼Ó×Ô½ç˵µÄÉèÖÃÏî £¬ÒÔ˳Ӧ²î±ðµÄÓªÒµÐèÇó¡£ÀýÈç £¬ÎÒÃÇÐèÒªÔÚÕû¸öÓ¦ÓÃÖнç˵һ¸ö³£Á¿ £¬¿ÉÒÔ½«³£Á¿½ç˵ÔÚ config.php ÎļþÖС£

define('APP_VERSION', '1.0.0');
return [
    'test' => 'hello world',
    'constant' => APP_VERSION,
    // ÆäËûÉèÖÃÏî
];

µÇ¼ºó¸´ÖÆ

È»ºóÔÚÓ¦ÓÃÖпÉÒÔͨ¹ý Config::get(‘constant’) À´»ñÈ¡½ç˵µÄ³£Á¿Öµ¡£

×ܽá

ÔÚÐÞ¸Ä ThinkPHP 5.0 ¿ò¼Üʱ £¬ÐèÒª¶Ô´úÂë½á¹¹ÓÐÒ»¶¨µÄÏàʶ £¬²¢ÇÒÔÚ¾ÙÐÐÐÞ¸ÄʱÐèҪעÖؼæÈÝÐԺͿÉÀ©Õ¹ÐÔ¡£ÈôÊDz»Ð¡ÐÄ·ºÆðÁ˼æÈÝÐÔÎÊÌâ £¬¿ÉÒÔͨ¹ýÉèÖÃÎļþÀ´½â¾ö¡£ÈôÊÇ·ºÆð¿ÉÀ©Õ¹ÐÔÎÊÌâ £¬¿ÉÒÔͨ¹ýÖØд¿ò¼ÜµÄ½¹µãÀà¿âÀ´½â¾ö¡£

ÒÔÉϾÍÊÇThinkPHP 5.0 ÖÐÔõÑù¾ÙÐÐÐ޸ĵÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ