thinkphp fetchÒªÁìÔõôÓÃ
Fetch method in ThinkPHP framework is a rendering method that is primarily used to load view pages and render them.¡£Ê×ÏÈÒªÕÒµ½ThinkPHP¿ò¼ÜÖеÄViewÀ࣬ÓÉÓÚÕâ¸öÒªÁìÊÇÔÚ¸ÃÀàÖнç˵µÄ¡£
ViewÀàÔÚThinkPHP¿ò¼ÜÖеÄ·¾¶ÈçÏ£º
thinkphp/library/think/View.php
µÇ¼ºó¸´ÖÆ
ÎÒÃÇ¿ÉÒÔͨ¹ýÕâ¸ö·¾¶ÕÒµ½ViewÀàËùÔÚµÄÔ´´úÂëÎļþ¡£ÔÚView.phpÔ´ÎļþÖУ¬ÓÐÒ»¸öViewÀ࣬ÆäÖнç˵ÁËfetch()ÒªÁìµÄ´úÂ룬ÈçÏÂËùʾ£º
/** * äÖȾģ°åÊä³ö * @access public * @param string $templateFile Ä£°åÎļþÃû * @param array $vars Ä£°åÊä³ö±äÁ¿ * @param array $config Ä£°å²ÎÊý * @return void * @throws Exception */ public function fetch($templateFile = '', $vars = [], $config = []) { // ½«±äÁ¿¸³Öµµ½ÊÓͼģ°åÖÐ if (!empty($vars)) { $this->assign($vars); } // ´¦ÀíÄ£°åÎļþÃû²¢ÅжÏÊÇ·ñ±£´æ $templateFile = $this->parseTemplateFile($templateFile); if (!is_file($templateFile)) { throw new Exception('template file not exists:' . $templateFile); } // Ä£°åÊä³ö¹ýÂË $this->filter($templateFile); // ÆÊÎöÊÓͼģ°åÖеĺ¯Êý $content = $this->fetchParse($templateFile, $config); // ÊÓͼģ°å±àÒ뻺´æ if ($this->config('tpl_cache') && !empty($TemplateCache)) { $TemplateCache->set($cacheFile, $content); } // ·µ»ØÆÊÎöºóµÄÊÓͼģ°åÄÚÈÝ return $content; }
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¶Î´úÂëÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½fetchÒªÁìµÄ½ç˵ºÍÏêϸʵÏÖ¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÔÚfetchÒªÁìÖУ¬ÎÒÃÇÊ×ÏÈʹÓÃassignÒªÁìת´ïÄ£°å±äÁ¿ºÍÒªäÖȾµÄÄ£°åÎļþÃû£¬ÒÔ¾ÙÐбäÁ¿¸³Öµ¡£½Ó×ÅÅжÏÄ£°åÎļþÊÇ·ñ±£´æ£¬ÈôÊDz»±£´æÔòÅ׳öÒì³£¡£×îºó£¬¾ÙÐÐÊÓͼģ°åÊä³ö¹ýÂË£¬ÆÊÎöÊÓͼģ°åÖеĺ¯Êý²¢·µ»Ø´¦ÀíºóµÄÄÚÈÝ¡£
ÒÔÉϾÍÊÇthinkphp fetchÒªÁìÔõôÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡