thinkphpÓÐÄÄЩÀà
thinkphpÊÇÒ»¿îÊ¢ÐеÄphp¿ò¼Ü£¬ËüÌṩÁËÐí¶àÓÐÓõÄÀ࣬ÓÃÓÚ¼ò»¯Õ¾µãºÍÓ¦ÓóÌÐòµÄ¿ª·¢¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝһЩ³£¼ûµÄthinkphpÀ࣬ÈÃÄú¸üºÃµØÏàʶÔõÑùʹÓÃÕâ¸ö¿ò¼ÜÀ´¹¹½¨webÓ¦ÓóÌÐò¡£
¿ØÖÆÆ÷Àà
¿ØÖÆÆ÷ÀàÊÇThinkPHP¿ò¼ÜÖÐ×îÖ÷ÒªµÄÀàÖ®Ò»¡£ËüÓÃÓÚ´¦ÀíHTTPÇëÇ󣬲¢ÇÒÔÚÏìӦʱ½«¿ØÖÆת´ï¸øÏà¹ØµÄÊÓͼ¡£
ÔÚThinkPHPÖУ¬¿ØÖÆÆ÷Ààͨ³£´æ´¢ÔÚappĿ¼µÄcontroller×ÓĿ¼ÖС£ÔÚ¿ØÖÆÆ÷ÀàÖУ¬Äú¿ÉÒÔ½ç˵Ðí¶à¹«¹²ÒªÁ죬ÕâЩҪÁìÓÃÓÚ´¦Àí²î±ðµÄHTTPÇëÇ󣬲¢ÇÒÔÚÏìӦʱ·ºÆðÏà¹ØµÄÊÓͼ¡£ÀýÈ磬ÒÔÏÂÊÇÒ»¸ö»ù±¾µÄUserControllerÀࣺ
namespace appcontroller; use thinkController; class UserController extends Controller { public function index() { // ´¦ÀíÊ×Ò³ÇëÇó return $this->fetch('index'); } public function login() { // ´¦ÀíµÇ¼ÇëÇó return $this->fetch('login'); } public function register() { // ´¦Àí×¢²áÇëÇó return $this->fetch('register'); } }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄʾÀýÖУ¬UserControllerÀà¼ÌÐøÁËControllerÀ࣬²¢½ç˵ÁËÈý¸ö¹«¹²ÒªÁ죺index()¡¢login()ºÍregister()¡£ÕâЩҪÁì»®·Ö´¦ÀíÖ÷Ò³¡¢µÇ¼ºÍ×¢²áÇëÇ󣬲¢ÔÚÏìӦʱ·µ»ØÏà¹ØµÄÊÓͼ¡£
Ä£×ÓÀà
Ä£×ÓÀàÊÇThinkPHP¿ò¼ÜÖÐÁíÒ»¸öÖ÷ÒªµÄÀà¡£Ëü±»ÓÃÓÚÖÎÀíÊý¾Ý£¬°üÀ¨ÅÌÎʺÍдÈëÊý¾Ý¿âÖеÄÊý¾Ý¡£Ä£×ÓÀàͨ³£ÓëÊý¾Ý¿âÖеıíÏà¹ØÁª¡£ÔÚThinkPHPÖУ¬¿ÉÒÔʹÓÃÄ£×ÓÀàÀ´Ö´ÐÐÖÖÖÖÊý¾Ý¿â²Ù×÷£¬ÀýÈç²åÈë¡¢¸üС¢É¾³ýºÍÅÌÎÊ¡£
ÒÔÏÂÊÇÒ»¸ö»ù±¾µÄUserÄ£×ÓÀàʾÀý£º
namespace appmodel; use thinkModel; class User extends Model { // ½ç˵±íÃû protected $table = 'user'; // ½ç˵Ö÷¼ü protected $pk = 'id'; // ½ç˵×Ö¶ÎÐÅÏ¢ protected $schema = [ 'id' => 'int', 'name' => 'string', 'email' => 'string', 'password' => 'string', ]; }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄʾÀýÖУ¬ÎÒÃǽç˵ÁËÒ»¸öUserÄ£×ÓÀà¡£¸ÃÀàÖ¸¶¨Á˸ÃÄ£×ÓÓ³Éäµ½µÄÊý¾Ý¿â±íÃû£¬Ö÷¼üÃû³ÆºÍ±í×Ö¶ÎÐÅÏ¢¡£ÕâЩÐÅÏ¢ÊÇʹÓÃprotected $table¡¢protected $pkºÍprotected $schemaÊôÐÔÀ´½ç˵µÄ¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÊÓͼÀà
ÊÓͼÀàÊÇÓÉ¿ØÖÆÆ÷Àà·ºÆðµÄ£¬ÓÃÓÚÔÚ¿Í»§¶Ëä¯ÀÀÆ÷ÖÐÏÔʾ¸øÓû§µÄÒ³Ãæ¡£ÔÚThinkPHPÖУ¬Äú¿ÉÒÔʹÓÃÊÓͼÀàÀ´½ç˵WebÓ¦ÓóÌÐòµÄ½á¹¹ºÍÑùʽ¡£
ÒÔÏÂÊÇÒ»¸ö»ù±¾µÄÄ£°åʾÀý£º
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>{% block title %}{% endblock %}</title> {% block head %}{% endblock %} </head> <body> {% block body %}{% endblock %} </body> </html>
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄʾÀýÖУ¬ÎÒÃǽç˵ÁËÒ»¸ö¼òÆÓµÄHTMLÒ³Ã档ʹÓÃ{% block %}Óï¾ä½ç˵ҳÃæµÄÎÊÌ⡢ͷ²¿ºÍÖ÷Ì壬ÕâЩÓï¾äÔÚ¿ØÖÆÆ÷ÀàÖоÙÐÐÌî³ä¡£
ÇëÇóÀà
ÇëÇóÀàÊÇÓÉ¿ØÖÆÆ÷ÀàʵÀý»¯µÄ¹¤¾ß£¬ËüʹÓÃHTTPÐÒ齫Êý¾Ý´Ó¿Í»§¶Ëä¯ÀÀÆ÷·¢Ë͵½WebÓ¦ÓóÌÐò¡£ÇëÇóÀà°üÀ¨ÓÐÓõÄÊôÐÔ£¬ÀýÈçÇëÇóµÄURL¡¢ÇëÇóµÄ²ÎÊýµÈ¡£
ÒÔÏÂÊÇÒ»¸ö»ù±¾µÄÇëÇóÀàʾÀý£º
use thinkRequest; $request = Request::instance(); echo $request->url(); // »ñÈ¡ÇëÇóµÄURL echo $request->method(); // »ñÈ¡ÇëÇóµÄÒªÁ죨GET¡¢POST¡¢PUTµÈ£© echo $request->param('name'); // »ñÈ¡ÃûΪ'name'µÄÇëÇó²ÎÊý
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄʾÀýÖУ¬ÎÒÃÇʹÓÃRequestÀà»ñÈ¡ÇëÇ󹤾ߣ¬²¢´òÓ¡ÁËһЩÓÐÓõÄÊôÐÔ¡£
ÏìÓ¦Àà
ÏìÓ¦ÀàÓÃÓÚ½«Êý¾Ý´ÓWebÓ¦ÓóÌÐò·¢Ëͻؿͻ§¶Ëä¯ÀÀÆ÷¡£ÏìÓ¦Àà°üÀ¨Ðí¶àÊôÐÔºÍÒªÁ죬ÀýÈçÏìÓ¦µÄ״̬Âë¡¢ÏìÓ¦µÄÍ·¡¢ÏìÓ¦µÄÕýÎĵȡ£
ÒÔÏÂÊÇÒ»¸ö»ù±¾µÄÏìÓ¦ÀàʾÀý£º
use thinkResponse; $response = new Response(); $response->code(200); // ÉèÖÃÏìӦ״̬ÂëΪ200 $response->header('Content-Type', 'text/html'); // ÉèÖÃÏìӦͷÐÅÏ¢ $response->content('Hello World!'); // ÉèÖÃÏìÓ¦ÕýÎÄÄÚÈÝ
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄʾÀýÖУ¬ÎÒÃÇʹÓÃResponseÀàÀ´½¨ÉèÏìÓ¦¹¤¾ß£¬²¢ÉèÖÃÏìӦ״̬Â롢ͷÐÅÏ¢ºÍÕýÎÄÄÚÈÝ¡£
½áÓï
ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÏÈÈÝÁËһЩ³£¼ûµÄThinkPHPÀ࣬°üÀ¨¿ØÖÆÆ÷Àࡢģ×ÓÀà¡¢ÊÓͼÀà¡¢ÇëÇóÀàºÍÏìÓ¦Àà¡£ÕâЩÀà¿ÉÒÔ×ÊÖúÄú¹¹Á¢¹¦Ð§Ç¿Ê¢µÄWebÓ¦ÓóÌÐò£¬¼ÓËÙ¿ª·¢ËÙÂÊ¡£ÈôÊÇÄúÏëÒªÉîÈëÏàʶThinkPHP¿ò¼ÜµÄ¸ü¶à֪ʶ£¬ÇëÉó²éThinkPHP¿ò¼ÜµÄ¹Ù·½Îĵµ¡£
ÒÔÉϾÍÊÇthinkphpÓÐÄÄЩÀàµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡