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

ThinkPHP5ÖÐÔõôŲÓÃÒªÁì

Ò»¡¢¿ØÖÆÆ÷ÖеÄÒªÁìŲÓÃ

¿ØÖÆÆ÷ÊÇÓ¦ÓóÌÐòÖд¦ÀíHTTPÇëÇó²¢Ïòä¯ÀÀÆ÷·¢ËÍÏìÓ¦µÄµØ·½¡£ThinkPHP5ÖеĿØÖÆÆ÷Ö÷ҪλÓÚappĿ¼Ï£¬¿ØÖÆÆ÷µÄÃüÃû¹æÔòÊÇÒÔÍÕ·åʽÃüÃû·¨£¬ÀýÈ磺UserController.php¡£ÔÚ¿ØÖÆÆ÷ÖУ¬ÎÒÃÇ¿ÉÒÔ½ç˵¶à¸öÒªÁìÀ´ÏìÓ¦²î±ðµÄÇëÇó¡£ÍÕ·åʽÃüÃû·¨Ó¦¸ÃÊÊÓÃÓÚÒªÁìÃû³Æ£¬È磺indexAction()¡£

ҪŲÓÿØÖÆÆ÷ÖеÄÒªÁ죬ÐèҪͨ¹ýURLÀ´»á¼û¡£URLÖеÄÓòÃûºÍ¶Ë¿ÚºÅºóÃæ½ôËæ×ŵÄÊÇ¿ØÖÆÆ÷µÄÃû³Æ£¬ÀýÈ磺http://example.com/UserController¡£¶ø»á¼û¿ØÖÆÆ÷ÖеÄÒªÁ죬ÔòÐèÒªÔÚURLºóÃæÌí¼ÓÒªÁìÃû³Æ£¬ÀýÈ磺http://example.com/UserController/index¡£

ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷ÒªÁìÖÐʹÓÃÄÚÖú¯ÊýÀ´»ñÈ¡HTTPÇëÇó²ÎÊý¡¢»á¼ûÊý¾Ý¿â¡¢Êä³öÄ£°åµÈ¡£ÀýÈ磬ÏÂÃæµÄ´úÂëÑÝʾÁËÔõÑù»ñÈ¡HTTPÇëÇóÖеIJÎÊý£º

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

public function index()
{
    $name = $this->request->param('name');
    $age = $this->request->param('age');
    echo "ÐÕÃû£º".$name."<br>ÄêË꣺".$age;
}

µÇ¼ºó¸´ÖÆ

¶þ¡¢Ä£×ÓÖеÄÒªÁìŲÓÃ

Ä£×ÓÊÇÓ¦ÓóÌÐòÖÐÈÏÕæÖÎÀíÊý¾ÝµÄµØ·½¡£ThinkPHP5ÖеÄÄ£×ÓλÓÚappĿ¼ÏµÄmodelĿ¼ÖУ¬Ä£×ÓµÄÃüÃû¹æÔòÊÇÒÔÍÕ·åʽÃüÃû·¨£¬ÀýÈ磺UserModel.php¡£

ÔÚÄ£×ÓÖУ¬ÎÒÃÇ¿ÉÒÔ½ç˵¶à¸öÒªÁìÀ´ÖÎÀíÊý¾Ý¡£ÒªÁìÃû³ÆӦʹÓÃÍÕ·åʽÃüÃû·¨£¬ÀýÈ磺getUserInfo()¡£

ÔÚ¿ØÖÆÆ÷ÖÐʵÀý»¯Ä£×Ó£¬ÒÔ´ËÀ´Å²ÓÃÄ£×ÓÖеÄÒªÁì¡£ÀýÈ磬ÏÂÃæµÄ´úÂëÑÝʾÁËÔõÑùÔÚ¿ØÖÆÆ÷ÖÐŲÓÃÄ£×ÓÖеÄÒªÁ죺

public function index()
{
    $userModel = new \app\model\UserModel();
    $userInfo = $userModel->getUserInfo(1);
    echo "ÐÕÃû£º".$userInfo['name']."<br>ÄêË꣺".$userInfo['age'];
}

µÇ¼ºó¸´ÖÆ

Èý¡¢ÊÓͼÖеÄÒªÁìŲÓÃ

ÊÓͼÊÇÓ¦ÓóÌÐòÖÐÈÏÕæչʾÊý¾ÝµÄµØ·½¡£ThinkPHP5ÖеÄÊÓͼλÓÚappĿ¼ÏµÄviewĿ¼ÖУ¬ÊÓͼµÄÃüÃû¹æÔòÊÇÒÔÍÕ·åʽÃüÃû·¨£¬²¢ÇÒÒÔ.tplΪºó׺Ãû£¬ÀýÈ磺userList.tpl¡£

ÔÚÊÓͼÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃÄÚÖú¯Êý»ò×Ô½ç˵º¯ÊýÀ´Õ¹Ê¾Êý¾Ý¡£ÏÂÃæµÄ´úÂëʾÀýչʾÁËÔõÑùÔÚÊÓͼÖÐŲÓÃÄÚÖú¯ÊýechoÊä³öÊý¾Ý£º

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Óû§Áбí</title>
</head>
<body>
    <table>
        <tr>
            <th>񅧏</th>
            <th>ÐÕÃû</th>
            <th>ÄêËê</th>
        </tr>
        <?php foreach($userList as $user) { ?>
        <tr>
            <td><?php echo $user['id']; ?></td>
            <td><?php echo $user['name']; ?></td>
            <td><?php echo $user['age']; ?></td>
        </tr>
        <?php } ?>
    </table>
</body>
</html>

µÇ¼ºó¸´ÖÆ

ÒÔÉϾÍÊÇThinkPHP5ÖÐÔõôŲÓÃÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ