thinkphpÔõô·â×°ÒªÁì
thinkphpÊÇÒ»¿îºÜÊÇÓÅÒìµÄphp¿ò¼Ü£¬ËüºÜÊÇÊʺÏÖÐСÐÍÆóÒµºÍСÎÒ˽¼Ò¿ª·¢ÕßʹÓá£ÔÚʹÓÃthinkphp¿ò¼Ü¾ÙÐпª·¢Ê±£¬ÎÒÃǾ³£»áÓöµ½ÐèÒªÖظ´Ê¹ÓõĹ¦Ð§Ä£¿é£¬ºÃ±È¶Ôij¸öÄ£×Ó¾ÙÐÐÔöɾ¸Ä²éµÈ²Ù×÷£¬Õâʱ¼äÎÒÃǾÍÐèÒª·âװһЩͨÓõÄÒªÁìÀ´ïÔÌ´úÂëµÄÈßÓ࣬Ìá¸ß´úÂëµÄ¿ÉÖØÓÃÐÔºÍά»¤ÐÔ¡£ÄÇô£¬±¾ÎľÍÀ´ÏÈÈÝÔõÑùÔÚthinkphp¿ò¼ÜÖзâ×°ÒªÁì¡£
Ò»¡¢Ê²Ã´ÊÇÒªÁì·â×°
ÒªÁì·â×°Ö¸µÄÊǽ«Ò»Ð©¾³£Ê¹ÓõĴúÂëÂß¼·â×°³ÉÒ»¸öÒªÁ죬Õâ¸öÒªÁì¿ÉÒÔÔÚ²î±ðµÄµØ·½±»Öظ´Å²Óã¬Æðµ½½ÚÔ¼´úÂëÁ¿¡¢Ìá¸ß´úÂë¿É¶ÁÐԺͿÉά»¤ÐÔµÄ×÷Óá£ÔÚThinkPHP¿ò¼ÜÖУ¬·â×°ÒªÁìÒ²ÊÇÒ»ÖÖ³£ÓõÄÊÖÒÕÊÖ¶ÎÖ®Ò»¡£
¶þ¡¢ThinkPHPÖÐÒªÁìµÄ·â×°
ÔÚThinkPHP¿ò¼ÜÖзâ×°ÒªÁ죬ÎÒÃÇÖ÷ÒªÊÇͨ¹ý½ç˵¿ØÖÆÆ÷»òÄ£×ÓÀ´ÊµÏֵġ£ÏÂÃæÎÒÃǾÍÒÔ¿ØÖÆÆ÷ΪÀý£¬¼òÆÓÏÈÈÝÒ»ÏÂÔõÑù·â×°ÒªÁì¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
½ç˵¿ØÖÆÆ÷
ÔÚThinkPHP¿ò¼ÜÖУ¬Ã¿¸ö¿ØÖÆÆ÷¶¼ÊÇÒ»¸öÀ࣬ÎÒÃÇͨ¹ý½ç˵¿ØÖÆÆ÷ÀàÀ´ÊµÏÖÒªÁìµÄ·â×°¡£Ê×ÏÈ£¬ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷ÀàµÄÍ·²¿¼ÓÉÏÃüÃû¿Õ¼äºÍÒýÓÃÀà¿âµÄ´úÂ룬ÈçÏÂËùʾ£º
namespace Home\Controller; use Think\Controller;
µÇ¼ºó¸´ÖÆ
½ç˵·â×°ÒªÁì
½Ó×Å£¬ÎÒÃÇÔÚ¿ØÖÆÆ÷ÀàÖнç˵һ¸ö·â×°ÒªÁ죬ÀýÈç½ç˵һ¸öÒªÁìÀ´ÅÌÎÊij¸öÄ£×ÓµÄÊý¾Ý£¬´úÂëÈçÏÂËùʾ£º
protected function getModelData($model){ //ʵÀý»¯Ä£×Ó $m = M($model); //ÅÌÎÊÊý¾Ý²¢·µ»Ø return $m->select(); }
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃǽç˵ÁËÒ»¸öÊܱ£»¤µÄÒªÁìgetModelData£¬Ëü½ÓÊÜÒ»¸ö×Ö·û´®²ÎÊý$model£¬ÌåÏÖÒªÅÌÎÊÊý¾ÝµÄÄ£×ÓÃû³Æ¡£ÔÚÒªÁìÖУ¬ÎÒÃÇÊ×ÏÈͨ¹ýMº¯ÊýʵÀý»¯ÁËÕâ¸öÄ£×Ó£¬È»ºóÓøÃÄ£×ÓÅÌÎÊÁËÊý¾Ý²¢·µ»ØÅÌÎÊЧ¹û¡£
ÐèҪעÖصÄÊÇ£¬ÓÉÓÚ´ËÒªÁìΪÊܱ£»¤µÄ£¬ÒÔÊÇÖ»ÄÜÔڸÿØÖÆÆ÷Öб»»á¼û¡£ÈôÊÇÐèÒªÔÚÆäËû¿ØÖÆÆ÷ÖÐÖØÓøÃÒªÁ죬ÔòÐèÒª½«Æä½ç˵Ϊ¹«¹²ÒªÁì¡£
ŲÓ÷â×°ÒªÁì
ÔÚ¿ØÖÆÆ÷ÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýŲÓ÷â×°ÒªÁìÀ´ÊµÏÖijЩ³£Óù¦Ð§£¬ÀýÈçÔÚIndex¿ØÖÆÆ÷ÖÐŲÓÃÉÏÃæ½ç˵µÄgetModelDataÒªÁ죬´úÂëÈçÏÂËùʾ£º
class IndexController extends Controller { public function index(){ //ŲÓ÷â×°ÒªÁì»ñÈ¡Ä£×ÓÊý¾Ý $data = $this->getModelData('User'); //äÖȾÊÓͼ $this->assign('data',$data); $this->display(); } }
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇÔÚIndex¿ØÖÆÆ÷µÄindexÒªÁìÖÐŲÓÃÁËgetModelDataÒªÁ죬´Ó¶ø»ñÈ¡ÁËUserÄ£×ÓµÄËùÓÐÊý¾Ý£¬²¢½«Æ丳ֵ¸øÊÓͼ¡£
ÒÔÉϾÍÊÇÔÚThinkPHP¿ò¼ÜÖÐÒªÁìµÄ·âװʵÏÖÒªÁìµÄÏÈÈÝ£¬Í¨¹ý·â×°ÒªÁ죬ÎÒÃÇ¿ÉÒÔÓÐÓõØïÔÌ´úÂëÈßÓ࣬Ìá¸ß´úÂëµÄ¿ÉÖØÓÃÐÔºÍά»¤ÐÔ¡£
ÒÔÉϾÍÊÇthinkphpÔõô·â×°ÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡