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

thinkphpÓï·¨ÔõôÕâô

ÄÑÃ÷£¿

ThinkPHP ÊÇÒ»¿î¿ªÔ´µÄ PHP ¿ª·¢¿ò¼Ü£¬ËüÌṩÁËÐí¶àÀû±ãµÄ¹¦Ð§ºÍ¹¤¾ß£¬Äܹ»´ó´óÌá¸ß PHP µÄ¿ª·¢Ð§ÂÊ¡£¿ÉÊÇ£¬ÔÚʹÓà ThinkPHP ¾ÙÐпª·¢µÄʱ¼ä£¬Ðí¶àÈ˾ͻáÓöµ½Ò»¸öÎÊÌ⣺thinkphp Óï·¨ÔõôÕâôÄÑÃ÷£¿

×Åʵ£¬thinkphp Óï·¨²¢²»ÊǺÜÄÑ£¬Ö»ÒªÄãÕÆÎÕÁËһЩ»ù±¾µÄ¿´·¨ºÍ¼¼ÇÉ£¬¾ÍÄܹ»ÇáËɵØʹÓÃËü¾ÙÐпª·¢¡£ÏÂÃ棬ÎÒÃǾÍÀ´Ò»ÆðÏàʶһÏ thinkphp µÄÓï·¨¡£

µÚÒ»£¬Ïàʶ MVC Éè¼Æģʽ

ÔÚʹÓà ThinkPHP ¾ÙÐпª·¢Ö®Ç°£¬Ê×ÏÈÒªÏàʶµÄÊÇËü½ÓÄɵÄÊÇ MVC Éè¼Æģʽ¡£MVC ÊÇÒ»ÖÖÈí¼þ¼Ü¹¹Ä£Ê½£¬ÓÃÓÚ½«Ó¦ÓóÌÐòµÄÊäÈë¡¢´¦ÀíºÍÊä³öÊèÉ¢¿ªÀ´£¬´Ó¶ø¸üºÃµØÖÎÀí´úÂëµÄ½á¹¹ºÍÂß¼­¡£ThinkPHP µÄ MVC Éè¼Æģʽ°üÀ¨Èý¸ö×é¼þ£º

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

Ä£×Ó£¨Model£©£ºÈÏÕæ´¦ÀíÊý¾ÝµÄÔöɾ¸Ä²é²Ù×÷£»

ÊÓͼ£¨View£©£ºÓÃÓÚÏÔʾÊý¾ÝºÍÓû§½çÃ棬ֻ¹ÜïÔÌ­Âß¼­´úÂëÓëÒ³Ãæ´úÂëµÄ»ìÔÓ£»

¿ØÖÆÆ÷£¨Controller£©£ºÖ÷ÒªÈÏÕæÓªÒµÂß¼­µÄ´¦Àí£¬ÅþÁ¬ÊÓͼºÍÄ£×Ó¡£

ÏàʶÁË MVC Éè¼Æģʽ֮ºó£¬ÎÒÃǾͿÉÒÔ¸üºÃµØÃ÷È· thinkphp µÄ´úÂë½á¹¹£¬´Ó¶øÔ½·¢ÇáËɵؿª·¢Ó¦ÓóÌÐò¡£

µÚ¶þ£¬ÕÆÎÕ thinkphp µÄ¿ØÖÆÆ÷

ThinkPHP µÄ¿ØÖÆÆ÷ÊÇÕû¸öÓ¦ÓóÌÐòµÄÈë¿Ú£¬ÈÏÕæÎüÊÕÓû§·¢³öµÄÇëÇó²¢¾ÙÐÐÏìÓ¦µÄ´¦Àí¡£ÔÚ¿ØÖÆÆ÷ÖУ¬¿ÉÒÔ½ç˵Ðí¶àÒªÁìÀ´´¦Àí²î±ðµÄÇëÇó¡£ÀýÈ磬ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷Öнç˵ index ÒªÁ죬ÓÃÓÚÏÔʾÖ÷Ò³£º

<?php
namespace appindexcontroller;

class Index
{
    public function index()
    {
        return 'Hello,ThinkPHP5!';
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚä¯ÀÀÆ÷ÖÐÊäÈë http://localhost/index.php/Index/index ¾Í¿ÉÒÔ»á¼û¿ØÖÆÆ÷Öнç˵µÄ index ÒªÁìÁË¡£

µÚÈý£¬Ïàʶ thinkphp µÄÄ£×Ó

ÔÚ ThinkPHP ÖУ¬Ä£×ÓÓÃÓÚÓëÊý¾Ý¿â½»»¥£¬¾ÙÐÐÊý¾ÝµÄÔöɾ¸Ä²é²Ù×÷¡£ÔÚʹÓÃÄ£×Ó֮ǰ£¬ÎÒÃÇÐèÒª¾ÙÐÐһЩÉèÖãº

ÔÚ application Ŀ¼Ï½¨ÉèÒ»¸ö model Ŀ¼£»

ÔÚ model Ŀ¼Ï½¨ÉèÒ»¸ö User.php Îļþ£¬ÓÃÓÚ½ç˵Óû§Ä£×Ó¡£

<?php
namespace appmodel;

use thinkModel;

class User extends Model
{
    protected $table = 'user';

    public function getUserByPhone($phone)
    {
        return $this->where('phone', $phone)->find();
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃǽç˵ÁËÒ»¸öÓû§Ä£×Ó User£¬²¢ÇÒ½ç˵ÁËÒ»¸ö getUserByPhone ÒªÁ죬ÓÃÓÚƾ֤ÊÖ»úºÅÂëÅÌÎÊÓû§ÐÅÏ¢¡£ÔÚÒªÁìÖУ¬ÎÒÃÇʹÓÃÁË $this->where() ÒªÁìÀ´¾ÙÐÐÊý¾Ý¿âÅÌÎʲÙ×÷¡£

µÚËÄ£¬Ñ§Ï° thinkphp µÄÊÓͼ

ÔÚ ThinkPHP ÖУ¬ÊÓͼÓÃÓÚÏÔʾÊý¾ÝºÍÓû§½çÃæ¡£ÔÚ¿ØÖÆÆ÷ÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÊÓͼÀ´Ïòä¯ÀÀÆ÷Êä³ö HTML ´úÂëºÍÊý¾Ý¡£ÀýÈ磺

<?php
namespace appindexcontroller;

class Index
{
    public function index()
    {
        $data = [
            'name' => 'ThinkPHP',
            'url' => 'https://www.thinkphp.cn/',
        ];
        return view('index', $data);
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇͨ¹ý view() ÒªÁì¼ÓÔØÁËÒ»¸öÃûΪ index µÄÊÓͼ£¬Í¬Ê±×ª´ïÁËÒ»¸öÊý×é²ÎÊý $data¡£

ÊÓͼÖÐʹÓà À´Êä³ö PHP ±äÁ¿ºÍ´úÂë¡£ÀýÈ磬ÔÚÊÓͼÖпÉÒÔÕâÑùÊä³ö $name ºÍ $url ±äÁ¿µÄÖµ£º

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title><?php echo $name ?></title>
</head>
<body>
    <h1><?php echo $name ?></h1>
    <a href="<?php echo $url ?>"><?php echo $url ?></a>
</body>
</html>

µÇ¼ºó¸´ÖÆ

µÚÎ壬ѧϰ thinkphp µÄ·ÓÉ

ÔÚ ThinkPHP ÖУ¬Â·ÓÉÊÇÖ¸½«Óû§ÇëÇóÖÐµÄ URL ·¾¶Ó³Éä³ÉÒ»¸ö¿ØÖÆÆ÷ÀàºÍÒªÁìµÄÀú³Ì¡£Â·ÓÉͨ³£ÓÐÁ½ÖÖ·½·¨£º

¾²Ì¬Â·ÓÉ£º½«Àο¿µÄ URL ·¾¶Ó³Éä³ÉÖ¸¶¨µÄ¿ØÖÆÆ÷ÀàºÍÒªÁ죻

¶¯Ì¬Â·ÓÉ£ºÆ¾Ö¤Óû§ÇëÇóÖеĶ¯Ì¬²ÎÊý£¬À´¶¯Ì¬Ó³Éä¿ØÖÆÆ÷ÀàºÍÒªÁì¡£

ÔÚ ThinkPHP ÖУ¬Â·Óɽç˵ÔÚ application/route.php ÎļþÖС£ÀýÈ磬ÎÒÃÇ¿ÉÒÔÔÚ·ÓÉÎļþÖнç˵һ¸ö¼òÆӵķÓÉ£º

<?php
use thinkacadeRoute;

//¾²Ì¬Â·ÓÉ
Route::get('hello/:name', 'index/hello');

//¶¯Ì¬Â·ÓÉ
Route::get(':controller/:action', 'index/:controller/:action');

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃǽç˵ÁËÒ»¸ö¾²Ì¬Â·ÓɺÍÒ»¸ö¶¯Ì¬Â·ÓÉ¡£¾²Ì¬Â·ÓÉÖÐµÄ :name ²ÎÊý£¬ÊÇÒ»¸ö¶¯Ì¬²ÎÊý£¬¿ÉÒÔÔÚ¿ØÖÆÆ÷ÖÐͨ¹ý $request->param(‘name’) À´»ñÈ¡¡£¶¯Ì¬Â·ÓÉÖÐµÄ :controller ºÍ :action ²ÎÊý£¬Ôò»®·Ö¶ÔÓ¦ÁË¿ØÖÆÆ÷ºÍÒªÁìµÄÃû³Æ¡£

×ܽá

ͨ¹ýÉÏÃæµÄÏÈÈÝ£¬ÐÅÍи÷ÈË¶Ô thinkphp µÄÓï·¨Ó¦¸ÃÓÐÁËһЩÏàʶ¡£×Åʵ£¬thinkphp µÄÓï·¨²¢²»ÄÑ£¬Ö»ÒªÕÆÎÕÁËһЩ»ù´¡ÖªÊ¶ºÍ¼¼ÇÉ£¬¾ÍÄܹ»ÇáËɵؾÙÐпª·¢¡£ÈôÊÇÄãÏëÒªÔ½·¢ÉîÈëµØѧϰ thinkphp£¬¿ÉÒԲο¼¹Ù·½ÎĵµºÍÆäËûÏà¹Ø×ÊÁÏ¡£

ÒÔÉϾÍÊÇthinkphpÓï·¨ÔõôÕâôµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ