ThinkPHPÖÐÔõÑùÉèÖýṹº¯Êý
Ò»¡¢Ê²Ã´Êǽṹº¯Êý
½á¹¹º¯ÊýÊÇÒ»¸öÔÚʵÀý»¯Ò»¸ö¹¤¾ßʱ×Ô¶¯Å²ÓõÄÌØÊ⺯Êý¡£ËüµÄ×÷ÓÃÊǶԹ¤¾ß¾ÙÐгõʼ»¯£¬ÉèÖÃÊôÐԵijõʼֵµÈ¡£ÔÚPHPÖУ¬½á¹¹º¯ÊýµÄÃû³Æ±ØÐèΪ__construct()¡£
¶þ¡¢ÔÚThinkPHPÖÐÉèÖýṹº¯ÊýµÄ°ì·¨
Ê×ÏÈÎÒÃÇÐèÒª½¨ÉèÒ»¸öÀàÎļþ£¬ºÃ±È˵ÎÒÃÇ¿ÉÒÔ½¨ÉèÒ»¸öPHPÎļþ£¬ÃüÃûΪtest.php£¬´úÂëÈçÏ£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
<?php namespace Home\Model; use Think\Model; class test extends Model{ private $name; public function __construct($name){ $this->name = $name; } public function get_name(){ return $this->name; } }
µÇ¼ºó¸´ÖÆ
ÔÚtestÀàÄÚÀһ¸ö˽ÓÐÊôÐÔ $name ±»½ç˵£¬Í¬Ê±ÉÐÓÐÒ»¸ö¹«¹²ÒªÁì get_name()¡£ÎÒÃÇʹÓÃ$name²ÎÊýÔڽṹº¯Êý__construct()ÖÐΪ$nameÊôÐÔ¸³³õÖµ¡£
ÔÚʹÓÃtestÀàµÄʱ¼ä£¬ÎÒÃÇ¿ÉÒÔÏñÏÂÃæÕâÑùʵÀý»¯¹¤¾ß£º
$t = new test("thinkphp"); echo $t->get_name();
µÇ¼ºó¸´ÖÆ
ÔÚʵÀý»¯¹¤¾ßµÄͬʱ£¬ÎÒÃÇת´ïÁËÒ»¸ö×Ö·û´®”thinkphp”×÷Ϊ²ÎÊý£¬Õâ¸ö²ÎÊý½«±»×ª´ï¸øÀàµÄ½á¹¹º¯Êý__construct()£¬²¢±»ÓÃÀ´ÉèÖÃÊôÐÔ$nameµÄ³õÖµ¡£×îÖÕ£¬ÎÒÃÇÓÃget_name()º¯ÊýÌáÈ¡$nameÊôÐÔµÄÖµ²¢¾ÙÐÐÊä³ö¡£
Èý¡¢Ê¹Óýṹº¯ÊýµÄÀûÒæ
ʹÓýṹº¯ÊýµÄÀûÒæÔÚÓÚ£¬¿ÉÒÔÔÚÀàʵÀý»¯µÄʱ¼ä¾ÍÍê³ÉһЩÐëÒªµÄ³õʼ»¯²Ù×÷£¬×èÖ¹ÁËÔÚʹÓÃÀàµÄʱ¼ä»¹ÒªÐ´Ò»Ð©ÌØÁíÍâ³õʼ»¯´úÂë¡£ÕâÑù£¬Ê¹ÓÃÆðÀ´Ò²Ô½·¢Àû±ã¡£
ÒÔÉϾÍÊÇThinkPHPÖÐÔõÑùÉèÖýṹº¯ÊýµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡