thinkphp5Ä£°åÖÐÔõôŲÓÿØÖÆÆ÷Îļþ
Ò»¡¢ThinkPHP 5 ÖеĿØÖÆÆ÷
ThinkPHP 5ÖеĿØÖÆÆ÷ÊÇÒ»¸öÖÁ¹ØÖ÷ÒªµÄ×é³É²¿·Ö£¬ÆäÖ÷ÒªÖ°ÔðÊÇÎüÊÕÇëÇó²¢×÷³öÏìÓ¦µÄÏìÓ¦¡£ÎÒÃÇ¿ÉÒÔͨ¹ýÔÚ¿ØÖÆÆ÷Öнç˵ҪÁìÀ´ÊµÏÖ²î±ðµÄÓªÒµÂß¼¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀý£º
namespace app\index\controller; class Index { public function index() { return 'Hello, World!'; } }
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃǽ¨ÉèÁËÒ»¸öControllerÃûΪIndex£¬²¢ÔÚÆäÖнç˵ÁËÒ»¸öMethodÃûΪindex¡£The method returns the string “Hello, World!”¡£ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃÇ»áʹÓøüΪÖØ´óµÄÒªÁìÀ´½ç˵²î±ðµÄÇëÇó´¦Àí·½·¨¡£
¶þ¡¢ThinkPHP 5 ÖеÄÄ£°åÒýÇæ
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÔÚThinkPHP 5ÖУ¬Ä£°åÒýÇæʹÓÃÁËÔÉúµÄPHPÓï·¨£¬»¹Ö§³ÖÐí¶à¿ØÖÆÓï¾äºÍ±äÁ¿Êä³öµÄÀ©Õ¹¡£ÔÚʹÓÃÄ£°åÒýÇæʱ£¬ÎÒÃÇÒ»Ñùƽ³£»á½«Ä£°åÎļþ´æ·ÅÔÚÊÓͼÎļþ¼ÐÖС£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄÊÓͼÎļþʾÀý£º
<!DOCTYPE html> <html> <head> <title>ŲÓÿØÖÆÆ÷ÒªÁì</title> </head> <body> <div class="container"> <h2><?php echo $title; ?></h2> <p><?php echo $content; ?></p> </div> </body> </html>
µÇ¼ºó¸´ÖÆ
ÔÚÒÔÉÏ´úÂëÖУ¬ÎÒÃǽç˵ÁËÒ»¸öÃûΪŲÓÿØÖÆÆ÷ÒªÁìµÄÊÓͼÎļþ£¬¸ÃÊÓͼÎļþ°üÀ¨ÁËÒ»¸öÎÊÌâ±äÁ¿ $title ºÍÒ»¸öÄÚÈݱäÁ¿ $content¡£ÕâÑùµÄÊÓͼÎļþºÜÊÇÊÊÊÊÓÃÓÚ¶¯Ì¬ÌìÉúÒ³ÃæµÄÇéÐΡ£
Èý¡¢ThinkPHP 5 ÖÐŲÓÿØÖÆÆ÷ÒªÁì
ÔÚThinkPHP 5ÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÄ£°åÎļþŲÓÿØÖÆÆ÷º¯Êý¡£ÔÚÊÓͼÎļþÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ·½·¨À´Å²ÓÿØÖÆÆ÷µÄÒªÁ죺
<?php echo url('¿ØÖÆÆ÷Ãû/ÒªÁìÃû'); ?>
µÇ¼ºó¸´ÖÆ
ÀýÈ磬ÎÒÃÇ¿ÉÒÔÔÚÊÓͼÎļþÖÐʹÓÃÒÔÏ´úÂëŲÓÃÉÏÎÄÖнç˵µÄIndex¿ØÖÆÆ÷µÄindexÒªÁ죺
<a href="<?php echo url('index/index'); ?>">Ìøתµ½indexÒ³Ãæ</a>
µÇ¼ºó¸´ÖÆ
ÈôÊÇÎÒÃÇÔÚä¯ÀÀÆ÷Öлá¼û¸ÃÊÓͼÎļþ£¬µã»÷¸ÃÁ´½Ó±ã»áÌøתµ½Index¿ØÖÆÆ÷µÄindexÒªÁìËùÖ¸ÏòµÄÒ³Ãæ¡£
¹ØÓÚÓжà¸ö²ÎÊýµÄÒªÁ죬ÎÒÃÇ¿ÉÒÔÔÚurl()º¯ÊýÖÐʹÓõڶþ¸ö²ÎÊýÀ´×ª´ï£º
<a href="<?php echo url('index/test', ['id' => 1, 'name' => 'test']); ?>">ת´ï²ÎÊýµ½testÒªÁì</a>
µÇ¼ºó¸´ÖÆ
ÔÚÒÔÉÏ´úÂëÖУ¬ÎÒÃÇÔÚurl()º¯ÊýµÄµÚ¶þ¸ö²ÎÊýÖÐת´ïÁËÒ»¸ö id ¼´ÊÇ 1¡¢name ¼´ÊÇ test µÄ²ÎÊýÁÐ±íµ½Index¿ØÖÆÆ÷µÄtestÒªÁì¡£
ÒÔÉϾÍÊÇthinkphp5Ä£°åÖÐÔõôŲÓÿØÖÆÆ÷ÎļþµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡