1¡¢¿Õ²Ù×÷
¿Õ²Ù×÷ÊÇָϵͳÔÚÕÒ²»µ½ÇeÇoµÄ²Ù×÷½¨µÄʱºo£¬»a¶¨Î»µ½¿Õ²Ù×÷£¨_empty
£(C)½¨À´Ö´ÐУ¬ÀuÓÃÕa¸o»uÖÆ£¬ÎÒÃÇ¿ÉÒÔʵÏÖ´iÎoÒ³ÃaeºÍÒ»Ð(C)URLµÄÓÅ»¯¡£
http://ÍøÖ*/index.php/Home/Main/login
http://ÍøÖ*/index.php/Home/Main/hello ¿Õ²Ù×÷
³oÏÖÒ³Ãae£º
ÏÔʾµÄ´iÎoÐÅÏ¢¹ýÓÚÏeϸ£¬Îª°²È«ÒÔ¼°ÓÅ»¯Ò³ÃaeÆð¼u£¬ÊµÐпղÙ×÷
1¡¢×oÒ»¸o_empty()½¨¡£ÒªÔÚ×ÓÀaÀiÃaeд£¬²»ÒªÔÙ¸¸ÀaÀi£¨ÍƼoʹÓã(C)
function _empty()
{
¡¡¡¡echo "ÍøÒ³²»´aeÔÚ£¬Çe¼i²ea¯ÀÀÆ÷µØÖ*ÐÅÏ¢£¡";
}
2.ÔiÒ»¸o¸Ã½¨¶ÔÓ¦µÄÄ£°ae
ÔÚview/mainÏÂÃaeн¨Ò»¸otext.htmlÎļþ
<body>
<h1>±ðÂÒ*ÃÎÊ</h1>
</body>
</html>
*×¢Òa£º¿Õ²Ù×÷½¨½oÔÚÄaµÄ¿ØÖÆÆ÷Àa¼Ì³ÐϵͳµÄThink\ControllerÀa²ÅÓÐЧ£¬ñÔoÐeÒª×Ô¼º¶¨Òa __call
À´ÊµÏÖ¡£**
2¡¢¿Õ¿ØÖÆÆ÷
¿Õ¿ØÖÆÆ÷µÄ¸ÅÄiÊÇÖ¸µ±ÏµÍ³ÕÒ²»µ½ÇeÇoµÄ¿ØÖÆÆ÷Ãu³ÆµÄʱºo£¬ÏµÍ³»a³¢ÊÔ¶¨Î»¿Õ¿ØÖÆÆ÷(EmptyController)£¬ÀuÓÃÕa¸o»uÖÆÎÒÃÇ¿ÉÒÔÓÃÀ´¶¨ÖÆ´iÎoÒ³ÃaeºÍ½øÐÐURLµÄÓÅ»¯¡£
Home/Controller/EmptyController.class.php
<?php
namespace Home\Controller;
use Think\Controller;
class EmptyController extends Controller
{
public function _empty()
{
echo "*ÃÎʵÄÒ³Ãae²»´aeÔÚ£¡";
}
}
3¡¢¿ç¿ØÖÆÆ÷µ÷ÓÃ
Ò»¸o¿ØÖÆÆ÷ÔÚÖ´ÐеÄʱºo£¬¿ÉÒÔʵÀý»¯ÁiÍaÒ»¸o¿ØÖÆ£¬²¢Í¨¹ý¶ÔÏoÃÎÊÆaÖ¸¶¨½*¨¡£
¿ç¿ØÖÆÆ÷µ÷ÓÿÉÒÔ½ÚÊ¡ÎÒÃÇ´uÂeµÄ¹¤×÷Á¿
3.1 ͬһģ¿eÏ£º
ÀýÈ磺ÔÚHome/ControllerÖÐÓÐÁ½¸o¿ØÖÆÆ÷£ºIndexController.class.phpºÍMainController.class.php
ÔÚIndexController.class.phpÓÐÒ»¸o½¨£º
public function ShuChu()
{
return "½ÌÎñ¹ÜÀiϵͳ£¡";
}
ÏÖÔÚÏeÒªÔÚ MainController.class.phpÖÐÒ²µ÷ÓÃShuChu()½¨
function DiaoYong()
{
//*½*¨Ò»£ºÔi¶ÔÏo
//$index=new IndexController();
//echo $index->ShuChu();
//Ôi¶ÔÏoÓпi½Ýº¯Êý¹(C)ÎÒÃÇʹÓãº
//A(¡°[Ä£¿e/]¿ØÖÆÆ÷±eÖ¾¡±) ʵÀý»¯¿ØÖÆÆ÷¶ÔÏo
//*½*¨¶þ£ºÊ¹ÓÃA()*½*¨
//$index=A("Index");
//echo $index->ShuChu();
//R([Ä£¿e/]¿ØÖÆÆ÷±eÖ¾/²Ù×÷*½*¨) ʵÀý»¯¶ÔÏoͬʱµ÷ÓÃÖ¸¶¨*½*¨
//*½*¨Èý£ºÊ¹ÓÃR()*½*¨,Ôi¶ÔÏo²¢ÇÒµ÷ÓÃij¸oÌض¨µÄ*½*¨
echo R("Index/ShuChu");
¡¡¡¡}
ÔËÐнa¹u£º
3.2 ²»Í¬Ä£¿eÏ£º
ÐÂÌi¼ÓÒ»¸oÄ£¿eAdmin
TextController.class.php:
<?php
namespace Admin\Controller;
use Think\Controller;
class TextController extends Controller
{
public function Text()
{
echo "HHHHH";
}
}
ÏÖÔÚÏeÒªÔÚHome/Controller/ MainController.class.phpÖÐÒ²µ÷ÓÃText()½¨
function Text()
{
//¿çÄ£¿eµ÷ÓÃ
//*½*¨Ò»£ºÊ¹ÓÃA()*½*¨
//$tt=A("Admin/Text");
//echo $tt->Text();
//*½*¨¶þ£ºÊ¹ÓÃR()*½*¨,Ôi¶ÔÏo²¢ÇÒµ÷ÓÃij¸oÌض¨µÄ*½*¨
echo R("Admin/Text/Text");
}
ÔËÐнa¹u£º
4.ÃuÃu¿Õ¼anamespace
Ïaµ±ÓÚÒ»¸oÐeÄaµÄĿ¼
Õý³£¹ÜÀiÎļþʹÓÃÎļþ¼Ð--ÎiÀiÇø*Ö
TP¿o¼ÜµÄ³oʼÃuÃu¿Õ¼aÊÇ£ºThinkPHP\Library
ÔÚTP¿o¼ÜÏÂÃuÃu¿Õ¼aÀiÃaeʹÓÃ\´u±iµÄÊdzoʼÃuÃu¿Õ¼a£¨ThinkPHP\Library£(C)
1.ϵͳĿ¼Ï¸uÃuÃu¿Õ¼aÊÇThinkPHP\LibraryÏÂÃaeµÄÎļþ¼ÐÃu³ÆÃuÃuµÄ
2.Ä£¿eµÄ¸uÃuÃu¿Õ¼aÊÇÒÔÄ£¿eÃuÃuÃuµÄ
ÔÚ¶¨ÒaÃuÃu¿Õ¼aµÄʱºoÐeÒª´Ó¸uдÆðÀýÈ磺Home\Controller ÀýÈç:Think\Model
Èç¹uҪʹÓÃij¸oÀaÎļþ£¬ÒýÈe¸ÃÀaÃuÃu¿Õ¼aµÄʱºo£º
ʹÓÃuse¹Ø¼u×Ö£¬ºoÃaeд¸ÃÀaµÄÃuÃu¿Õ¼a ºoÃae¼ÓÉÏ "\ÎļþÃu"
Èç¹u²»ÏeÒýÈeÃuÃu¿Õ¼a£ºÔÚÔiÀaµÄ¶ÔÏoµÄʱºo¿ÉÒÔʹÓÃ\£¨³oʼÃuÃu¿Õ¼a£(C)À´ÕÒµ½¶ÔÓ¦µÄÀa
ÀýÈ磺new \Think\Page(30);
ÒÔÉÏÕaƪThinkphp ¿Õ²Ù×÷¡¢¿Õ¿ØÖÆÆ÷¡¢ÃuÃu¿Õ¼a(Ïe½a)¾ÍÊÇС±a*ÖÏi¸ø´o¼ÒµÄÈ«²¿ÄÚÈÝÁË£¬Ï£ÍuÄܸø´o¼ÒÒ»¸o²Î¿¼£¬Ò²Ï£Íu´o¼Ò¶a¶aÖ§³Ö½Å±¾Ö®¼Ò¡£