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

thinkphpÔõÑùʵÏÖ

thinkphpÊÇÒ»¸ö¿ªÔ´µÄphp¿ª·¢¿ò¼Ü £¬ËüÊܵ½ÁËÐí¶àphp³ÌÐòÔ±µÄ×·ÅõºÍʹÓá£Ëü×÷Ϊһ¸ö³ÉÊì¶øÓÖÎȹ̵Ŀò¼Ü £¬ÎªÎÒÃÇÌṩÁ˺ÜÊÇÇ¿Ê¢µÄ¹¤¾ßºÍ¿ª·¢×ÊÔ´¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚthinkphp¿ò¼ÜÖÐʵÏÖһЩ³£¼ûµÄ¹¦Ð§¡£

Ò»¡¢ÔõÑù½¨Éè¿ØÖÆÆ÷

ÔÚThinkPHPÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃÈçÏÂÏÂÁîÀ´½¨ÉèÒ»¸ö¿ØÖÆÆ÷£º

php think make:controller Index

µÇ¼ºó¸´ÖÆ

¸ÃÏÂÁÔÚÓ¦ÓÃĿ¼ÏµÄcontrollerĿ¼Öн¨ÉèÒ»¸öÃûΪIndexµÄ¿ØÖÆÆ÷¡£ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷Öнç˵ÏêϸµÄÓªÒµÂß¼­ÊµÏÖ¡£

¶þ¡¢ÔõÑù½¨ÉèÄ£×Ó

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

ÔÚThinkPHPÖÐ £¬Ä£×ÓÊÇÓÃÓÚ´¦ÀíÊý¾Ý¿â²Ù×÷µÄ¡£ÎÒÃÇ¿ÉÒÔʹÓÃÈçÏÂÏÂÁîÀ´½¨ÉèÒ»¸öÄ£×Ó£º

php think make:model User

µÇ¼ºó¸´ÖÆ

¸ÃÏÂÁÔÚÓ¦ÓÃĿ¼ÏµÄmodelĿ¼Öн¨ÉèÒ»¸öÃûΪUserµÄÄ£×Ó¡£ÎÒÃÇ¿ÉÒÔÔÚÄ£×ÓÖнç˵ÏêϸÊý¾Ý¿â²Ù×÷ʵÏÖ¡£

Èý¡¢ÔõÑù½¨ÉèÊÓͼ

ÔÚThinkPHPÖÐ £¬ÊÓͼÓÃÓÚչʾÊý¾ÝºÍÍê³ÉÓû§½»»¥¡£ÎÒÃÇ¿ÉÒÔʹÓÃÈçÏÂÏÂÁîÀ´½¨ÉèÒ»¸öÊÓͼ£º

php think make:view Index/index

µÇ¼ºó¸´ÖÆ

¸ÃÏÂÁÔÚÓ¦ÓÃĿ¼ÏµÄviewĿ¼Öн¨ÉèÒ»¸öÃûΪindex.htmlµÄÊÓͼ¡£ÔÚÕâ¸öÊÓͼÖÐ £¬ÎÒÃÇ¿ÉÒÔ½ç˵ÏêϸµÄÒ³ÃæչʾЧ¹ûºÍ½»»¥Ê½ÔªËØ¡£

ËÄ¡¢ÔõÑù½ç˵·ÓÉ

ÔÚThinkPHPÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓ÷ÓÉÀ´½ç˵URL»á¿´·¨Ö·Óë¿ØÖÆÆ÷ÒªÁìµÄÓ³Éä¹Øϵ¡£ÎÒÃÇ¿ÉÒÔÔÚÓ¦ÓÃĿ¼ÏµÄrouteĿ¼Öн¨ÉèÒ»¸öroute.phpÎļþ £¬²¢Ìí¼ÓÈçÏÂÄÚÈÝ£º

<?php
use thinkacadeRoute;

Route::get('user/:id', 'index/user');

µÇ¼ºó¸´ÖÆ

¸Ã´úÂë½ç˵ÁËÒ»¸öURLÓ³Éä¹Øϵ £¬½«URL/user/10Ó³Éäµ½index¿ØÖÆÆ÷ÖеÄuserÒªÁì £¬ÆäÖÐ10ÊÇÓû§ID²ÎÊý¡£

Îå¡¢ÔõÑùʹÓÃÖÐÑë¼þ

ÔÚThinkPHPÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃÖÐÑë¼þÀ´¾ÙÐÐ×èµ²¡¢Ð£ÑéºÍÉèÖá£ÎÒÃÇ¿ÉÒÔÔÚÓ¦ÓÃĿ¼ÏµÄmiddlewareĿ¼Öн¨ÉèÒ»¸öÃûΪTestMiddlewareµÄÖÐÑë¼þ £¬²¢Ìí¼ÓÈçÏ´úÂ룺

<?php
namespace appmiddleware;

class TestMiddleware
{
    public function handle($request, Closure $next)
    {
        // ÖÐÑë¼þÂß¼­´¦Àí
        return $next($request);
    }
}

µÇ¼ºó¸´ÖÆ

¸Ã´úÂë½ç˵ÁËÒ»¸öÃûΪTestMiddlewareµÄÖÐÑë¼þ £¬ÔÚÖ´ÐзÓɲÙ×÷ʱ £¬½«»áÏÈÖ´ÐиÃÖÐÑë¼þµÄhandleÒªÁì¡£

Áù¡¢ÔõÑù¾ÙÐÐÊý¾Ý¿â²Ù×÷

ÔÚThinkPHPÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃDbÀàÀ´¾ÙÐÐMySQLÊý¾Ý¿âµÄ²Ù×÷¡£ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷»òÄ£×ÓÖÐÌí¼ÓÈçÏ´úÂ룺

<?php
namespace appcontroller;

use thinkacadeDb;

class User
{
    public function getUser($id)
    {
        return Db::table('user')
                    ->where('id', $id)
                    ->find();
    }
}

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂë½ç˵ÁËÒ»¸ö¿ØÖÆÆ÷ÒªÁì £¬ÓÃÓÚ´ÓÊý¾Ý¿âÖлñÈ¡Óû§ÐÅÏ¢¡£

Æß¡¢ÔõÑùʹÓûº´æ

ÔÚThinkPHPÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓûº´æÀ´Ìá¸ß³ÌÐòµÄÐÔÄܺÍÓÅ»¯¡£ÎÒÃÇ¿ÉÒÔʹÓÃcacheº¯ÊýÀ´¾ÙÐлº´æ²Ù×÷£º

cache('user_'.$id, $user);

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂëÌåÏÖ½«$user¹¤¾ß»º´æµ½Ãû³ÆΪuser_10µÄ»º´æÖС£

°Ë¡¢ÔõÑùʹÓÃÈÕÖ¾

ÔÚThinkPHPÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃÈÕÖ¾¼Í¼³ÌÐòÔËÐÐÀú³ÌÖеÄÐÅÏ¢ºÍÒì³£¡£ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷»òÄ£×ÓÖÐÌí¼ÓÈçÏ´úÂ룺

<?php
namespace appcontroller;

use thinkacadeLog;

class User
{
    public function getUser($id)
    {
        Log::info('ÅÌÎÊÓû§ÐÅÏ¢ÀÖ³É');
        return Db::table('user')
                    ->where('id', $id)
                    ->find();
    }
}

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂëÌåÏÖÔÚ¿ØÖÆÆ÷ÖÐÅÌÎÊÓû§ÐÅÏ¢µÄͬʱ £¬¼Í¼һÌõÃûΪinfoµÄÈÕÖ¾ÄÚÈÝ¡£

×ÛÉÏËùÊö £¬ÒÔÉÏÊÇһЩ³£ÓõÄThinkPHP¿ò¼Ü²Ù×÷¡£ÔÚʵ¼ùÖÐ £¬¿ÉÒÔƾ֤ÏêϸÐèÇóÏìÓ¦µ÷½âºÍÐÞÕý¡£Ð»Ð»Äú¶ÔThinkPHP¿ò¼ÜµÄÖ§³ÖºÍʹÓá£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ