thinkphpÖÐÒªÁìŲÓÃ
thinkphpÊÇÒ»¸öÓÅÒìµÄphp¿ª·¢¿ò¼Ü£¬ËüÔÚÒªÁìŲÓÃÉÏÌṩÁËÐí¶àÀû±ãµÄ¹¦Ð§£¬±¾ÎĽ«ÎªÄãÏÈÈÝÆäÖеÄһЩҪÁìŲÓÃÒªÁì¡£
Ò»¡¢¿ØÖÆÆ÷ÒªÁìŲÓÃ
ÔÚThinkPHPÖУ¬¿ØÖÆÆ÷ÊÇMVC¿ò¼ÜÖеĽ¹µã´úÂëÖ®Ò»¡£¿ØÖÆÆ÷ÖÐÓÐÐí¶à¿É¹©Ê¹ÓõÄÒªÁì¡£ÎÒÃÇ¿ÉÒÔÏñÏÂÃæÕâÑùÔÚ¿ØÖÆÆ÷Öнç˵һ¸öÒªÁ죺
public function index(){ echo 'ÕâÊÇ¿ØÖÆÆ÷ÖеÄindexÒªÁì'; }
µÇ¼ºó¸´ÖÆ
È»ºóÎÒÃÇ¿ÉÒÔÔÚä¯ÀÀÆ÷ÖÐÊäÈëÍøÖ·À´Å²ÓÃÕâ¸öÒªÁ죺
http://localhost/tp5/index.php/index/index
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬index.phpÊÇThinkPHP¿ò¼ÜµÄÈë¿ÚÎļþ£¬indexÊÇ¿ØÖÆÆ÷Ãû³Æ£¬indexÊǸÿØÖÆÆ÷µÄÒªÁìÃû³Æ¡£ÕâÀïÐèҪעÖصÄÊÇ£¬ÔÚThinkPHP5¿ò¼ÜÖУ¬ÓÉÓÚ·Óɵı£´æ£¬ÉÏÃæµÄÍøÖ·¿ÉÒÔ¼ò»¯Îª£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
http://localhost/tp5/public/index/index
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬tp5ÊÇÏîÄ¿µÄ¸ùĿ¼Ãû³Æ£¬publicÊÇÏîÄ¿µÄÈë¿ÚĿ¼Ãû³Æ¡£
¶þ¡¢Ä£×ÓÒªÁìŲÓÃ
ÔÚThinkPHPÖУ¬Ä£×ÓÊÇÅþÁ¬¿ØÖÆÆ÷ºÍÊý¾Ý¿âÖ®¼äµÄÇÅÁº¡£ÔÚÄ£×ÓÖУ¬ÎÒÃÇ¿ÉÒÔ½ç˵Ðí¶à³£ÓõÄÒªÁìÀ´²Ù×÷Êý¾Ý¿â£¬ÀýÈçÔöɾ¸Ä²éµÈ¡£ÎÒÃÇ¿ÉÒÔÏñÏÂÃæÕâÑùÔÚÄ£×ÓÖнç˵һ¸öÒªÁ죺
public function getList(){ $list = $this -> select(); return $list; }
µÇ¼ºó¸´ÖÆ
Õâ¸öÒªÁì¿ÉÒÔÓÃÀ´ÅÌÎÊÊý¾Ý¿âÖеļͼ£¬²¢·µ»ØÒ»¸öÊý×é¡£ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷ÖÐŲÓÃÕâ¸öÒªÁìÀ´»ñÈ¡ÅÌÎÊЧ¹û£º
public function index(){ $model = new DemoModel(); $list = $model -> getList(); $this -> assign('list', $list); return $this -> fetch(); }
µÇ¼ºó¸´ÖÆ
ÔÚÅÌÎÊÀֳɺó£¬ÎÒÃǽ«Ð§¹û¸³Öµ¸øÄ£°å£¬È»ºóʹÓÃfetch()ÒªÁìÀ´ÏÔʾÅÌÎÊЧ¹û£¬ÒÔÊÇÎÒÃÇ¿ÉÒÔÔÚÄ£°åÖÐʹÓÃlist±äÁ¿À´ÏÔʾÅÌÎÊЧ¹û¡£
Èý¡¢ÖúÊÖº¯ÊýŲÓÃ
ÔÚThinkPHPÖУ¬ÖúÊÖº¯ÊýÊÇÒ»×é¼òÆӵĺ¯Êý£¬ËüÃÇ¿ÉÒÔÓÃÀ´´¦Öóͷ£ÏîÄ¿Öеij£ÓòÙ×÷¡£ÕâЩº¯Êý¶¼±»½ç˵ÔÚÎļþhelper.phpÖУ¬ÎÒÃÇ¿ÉÒÔÖ±½ÓŲÓÃÕâЩº¯ÊýÀ´Íê³ÉһЩ²Ù×÷¡£ÀýÈ磺
$data = [ 'name' => 'ThinkPHP', 'email' => 'thinkphp@qq.com', ]; dump($data);
µÇ¼ºó¸´ÖÆ
Õâ¸öÀý×ÓʹÓÃÁËdump()º¯ÊýÀ´Õ¹Ê¾$dataÊý×éµÄÄÚÈÝ¡£dump()º¯ÊýÊÇÒ»¸öºÜÊǺÃÓõÄÖúÊÖº¯Êý£¬Ëü¿ÉÒÔÓÃÀ´´òÓ¡Êý¾ÝµÄ½á¹¹ºÍÄÚÈÝ¡£
ËÄ¡¢TPÄÚÖÃÒªÁìŲÓÃ
³ýÁËÒÔÉϵÄÓ÷¨£¬ThinkPHP»¹ÌṩÁËһЩÆäËûµÄÒªÁìŲÓ÷½·¨£¬ÀýÈ磺
TPµÄÈÕÖ¾ÒªÁ죺
ÔÚThinkPHPÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃLogÀàÀ´¼Í¼ϵͳÈÕÖ¾¡£ÀýÈ磺
Log::record('ÕâÊÇÒ»ÌõϵͳÈÕÖ¾');
µÇ¼ºó¸´ÖÆ
Õâ¸öÒªÁ콫»áÍùϵͳÈÕÖ¾ÎļþÖÐдÈëÒ»Ìõ¼Í¼¡£
TPµÄ»º´æÒªÁ죺
ÔÚThinkPHPÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃCacheÀàÀ´ÊµÏÖ»º´æ¹¦Ð§¡£ÀýÈ磺
Cache::set('name', 'Tom', 3600);
µÇ¼ºó¸´ÖÆ
Õâ¸öÒªÁì¿ÉÒÔ½«Êý¾Ý»º´æµ½CacheÖУ¬²¢ÉèÖÃÓÐÓÃÆÚΪ3600Ãë¡£
Èý¡¢×ܽá
ͨ¹ýÒÔÉϵÄÏÈÈÝ£¬ÎÒÃÇ¿ÉÒÔ¿´µ½£¬ThinkPHPÌṩÁËÐí¶àÀû±ãµÄÒªÁìŲÓ÷½·¨£¬Äܹ»×ÊÖúÎÒÃǸüºÃµØÍê³ÉÏîÄ¿ÖеIJÙ×÷¡£ÎÒÃÇÒªÊìÁ·ÕÆÎÕÕâЩҪÁìµÄʹÓ㬲Żª¸üºÃµØʹÓÃThinkPHP¿ò¼Ü¾ÙÐпª·¢¡£
ÒÔÉϾÍÊÇthinkphpÖÐÒªÁìŲÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡