PHP MVC ѧϰ ThinkPHP
1.ʲôÊÇMVC£¿
MVC±¾À´ÊÇ´æÔÚÓÚDesktop£¨×ÀÃ棩³ÌÐòÖеģ¬MÊÇÖ¸Êý¾ÝÄ£ÐÍ£¬VÊÇÖ¸Óû§½çÃ棬CÔòÊÇ¿ØÖÆÆ÷¡£Ê¹ÓÃMVCµÄÄ¿µÄÊǽ«MºÍVµÄʵÏÖ´úÂë·ÖÀë¡£MVCÊÇÒ»¸öÉè¼Æģʽ£¬ËüÇ¿ÖÆÐÔµÄʹӦÓóÌÐòµÄÊäÈ룬´¦ÀíºÍÊä³ö·Ö¿ª¡£Ê¹ÓÃMVCÓ¦ÓóÌÐò±»·ÖΪÈý¸öºËÐIJ¿¼þ£ºÄ£ÐÍ£¬ÊÔͼ£¬¿ØÖÆÆ÷¡£ËüÃǽ«´¦Àí×Ô¼ºµÄÈÎÎñ¡£
2.ΪʲôҪʹÓÃMVC?
Ê×ÏÈ£¬×îÖØÒªµÄÒ»µãÊǶà¸öÊÓͼÄܹ²ÏíÒ»¸öÄ£ÐÍ£¬ÏÖÔÚÐèÒªÓÃÔ½À´Ô½¶àµÄ·½Ê½À´·ÃÎÊÄãµÄÓ¦ÓóÌÐò¡£ÓÉÓÚÄ£ÐÍ·µ»ØµÄÊý¾ÝûÓнøÐиñʽ»¯£¬ËùÒÔͬÑùµÄ¹¹¼þÄܱ»²»Í¬½çÃæʹÓá£ÔٴΣ¬¿ª·¢ÖÜÆÚËõ¶Ì£¬·½±ãά»¤ºÍ¹ÜÀí½µµÍ¿ª·¢³É±¾ºÍ¹¤×÷Á¿¡£
MVCµÄȱµãÊÇÓÉÓÚËüûÓÐÃ÷È·µÄ¶¨Ò壬ËùÒÔÍêÈ«Àí½âMVC²¢²»ÊǺÜÈÝÒס£Ê¹ÓÃMVCÐèÒª¾«Ðĵļƻ®£¬ÓÉÓÚËüµÄÄÚ²¿ÔÀí±È½Ï¸´ÔÓ£¬ËùÒÔÐèÒª»¨·ÑһЩʱ¼äȥ˼¿¼¡£
MVC²¢²»ÊʺÏСÐÍÉõÖÁÖеȹæÄ£µÄÓ¦ÓóÌÐò£¬»¨·Ñ´óÁ¿Ê±¼ä½²MVCÓ¦Óõ½¹æÄ£²¢²»ÊǺܴóµÄÓ¦ÓóÌÐòͨ³£»áµÃ²»³¥Ê§¡£
3.ÈÏʶһ¸öMVC¿ò¼ÜThinkPHP
ThinkPHPÊÇÒ»¸ö¿ìËÙ£¬¼òµ¥µÄÃæÏò¶ÔÏóµÄÇáÁ¿¼¶PHP¿ª·¢¿ò¼Ü£¬×ñÑApache2¿ªÔ´ÐÒé·¢²¼£¬²¢ÇÒÓÀ¾ÃÃâ·ÑʹÓã¬ÊÇΪ¼ò»¯ÆóÒµ¼¶Ó¦Óÿª·¢ºÍÃô½ÝWEBÓ¦Óÿª·¢¶øµ®ÉúµÄ¡£Ê¹ÓÃThinkPHP£¬Äã¿ÉÒÔ¸ü·½±ãºÍ¿ì½ÝµÄ¿ª·¢ºÍ²¿ÊðWEBÓ¦Óá£
Ìص㣺
¼òµ¥Ò×ÓõÄMVCģʽ ¶À´´µÄºËÐıàÒëºÍÏîÄ¿±àÒë»úÖÆ ÄÚÖÃXMLÄ£°åÒýÇ棬֧³Ö±êÇ©¿â¸»Ä£ÐÍÖ§³Ö
Ŀ¼½á¹¹×Ô¶¯´´½¨ ·Ö²¼Ê½Êý¾Ý¿âÖ§³Ö ¶àÊý¾Ý¿âÁ¬½ÓºÍÇл»Ö§³Ö CURDºÍ²Ù×÷¸ß¶È×Ô¶¯»¯Ö§³Ö
4.ÈçºÎ´î½¨Ò»¸öThinkPHP
ÏÂÔØThinkPHP¿ò¼Ü°ü£¬Ö±½ÓÒýÓÃĿ¼ÖеÄThinkPHP.phpÎļþ¼´¿É
index.php
<?php
define('THINK_PATH','ThinkPHP/');
define('APP_NAME','phpName');
define('APP_PATH','.');
require(THINK_PATH."/ThinkPHP.php");
$App=new App();//ʵÀý»¯²Ù×÷ϵͳ»á×Ô¶¯´´½¨¿ª·¢Ä¿Â¼
$App->run();
?>
5.ThinkPHPµÄ¼òµ¥Ê¹ÓÃ
£¨1£©ThinkPHPÈçºÎ´´½¨Ò»¸ö¿ØÖÆÆ÷
Ö»ÐèÔÚLib\ActionĿ¼Ï´´½¨Ò»¸ö¶ÔÓ¦µÄ¿ØÖÆÆ÷µÄÀà¸ñʽname.class.php
(2)ThinkPHP URL·ÓÉÄ£µÄ½âÎö
²ÉÓõ¥Ò»Èë¿Ú·½Ê½£¬ÌṩÁËÒ»¸öURL·ÓÉģʽ½âÎö/
Ö´ÐÐÉÏÃæµÄindex.php»á×Ô¶¯´´½¨ºÃĿ¼¡£
6.ThinkPHPÅäÖÃÎļþ
\ThinkPHP\Common\conwention.php
'DEFAULT_MODULE'=>'index',//ĬÈÏÄ£¿éÃû³Æ
'DEFAULT_ACTION'=>'index',//ĬÈϲÙ×÷Ãû³Æ
'DEBUG_MODE'=>false,//µ÷ÊÔģʽĬÈϹرÕ
//¹ßÀýÅäÖö¨Òå±äÁ¿Ãû´óСдÈÎÒ⣬¶¼»áËûżÄǸöһת»»³ÉСд
//
Ïà¹ØÎĵµ£º
Ò»¡¢ÎÊÌâÆðÔ´
ÉÔ´óһЩµÄÍøÕ¾£¬Í¨³£¶¼»áÓкü¸¸ö·þÎñÆ÷£¬Ã¿¸ö·þÎñÆ÷ÔËÐÐ×Ų»Í¬¹¦ÄܵÄÄ£¿é£¬Ê¹Óò»Í¬µÄ¶þ¼¶ÓòÃû£¬¶øÒ»¸öÕûÌåÐÔÇ¿µÄÍøÕ¾£¬Óû§ÏµÍ³ÊÇͳһµÄ£¬¼´Ò»Ì×
Óû§Ãû¡¢ÃÜÂëÔÚÕû¸öÍøÕ¾µÄ¸÷¸öÄ£¿éÖж¼ÊÇ¿ÉÒԵǼʹÓõġ£¸÷¸ö·þÎñÆ÷¹²ÏíÓû§Êý¾ÝÊDZȽÏÈÝÒ×ʵÏֵģ¬Ö»ÐèÒªÔÚºó¶Ë·Å¸öÊý¾Ý¿â·þÎñÆ÷£¬¸÷¸ö·þÎñÆ÷ͨ¹ýͳһ½Ó
......
¹ØÓÚÔÚAJAXÖÐGET»ØµÄResponseTextÖÐÎÄÂÒÂëµÄ×î¼ò½â¾ö°ì·¨
//Èç¹û´«ËͲÎÊýÊÇÖ±½Ó¸³ÓèµÄ£¬¾Í»á²úÉúÂÒÂë!
´úÂëÈçÏÂ:
http_request.open("POST",url,true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send("action="+strName+"&val="+val); //Èç¹ûvalµÄ ......
function multi($num, $perpage, $curpage, $mpurl) {
$multipage = '';
$mpurl .= strpos($mpurl, '?') ? '&' : '?';
if($num > $perpage) {
$page = 10;
$offset = 5;
$pages = @ceil($num / $perpage);
if($pag ......
The define() function defines a constant.
define()º¯ÊýµÄ×÷ÓÃÊÇ£º¶¨ÒåÒ»¸ö³£Á¿¡£
Constants are much like variables, except for the following differences:
³£Á¿[constant]Óë±äÁ¿[variable]ÓкܶàÏàËƵĵط½£¬Òò´Ë£¬ºÜÈÝÒ×»ìÏý£»ÏÂÃ棬ÎÒÃÇÁоÙһϳ£Á¿[constant]Óë±äÁ¿[variable]Ö®¼äµÄ²»Í¬µã£º
A constant's ......
תÔØ×Ô£ºhttp://www.ibm.com/developerworks/cn/opensource/os-php-5.3unicode/index.html
Web
ÊÇÒ»¸öÓÃÀ´¿ª·¢È«ÇòÐÔÓ¦ÓóÌÐòºÍ·þÎñµÄÀíÏëƽ̨¡£Òª´´½¨Ò»¸öÕæÕý¾ßÓйú¼Ê÷ÈÁ¦µÄÓ¦ÓóÌÐò£¬±ØÐë¶ÔËü½øÐе÷ÕûÒÔ±ãÄܹ»ÒÔ¸÷ÖÖÓïÑԺͱàдϵͳ´¦ÀíºÍÏÔʾÊý¾Ý¡£
³£ÓÃËõд´Ê
HTML£º
³¬Îı¾±ê¼ÇÓïÑÔ
HTTP£º
³¬Îı¾´« ......