论坛首页 编程语言技术论坛

smarty什么时候会从新编译template

浏览 3071 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-01-09  
PHP
从smarty.class.php文件中的下列代码可以看出来:

   /**
     * test if resource needs compiling
     *
     * @param string $resource_name
     * @param string $compile_path
     * @return boolean
     */
    function _is_compiled($resource_name, $compile_path)
    {
        if (!$this->force_compile && file_exists($compile_path)) {
            if (!$this->compile_check) {
                // no need to check compiled file
                return true;
            } else {
                // get file source and timestamp
                $_params = array('resource_name' => $resource_name, 'get_source'=>false);
                if (!$this->_fetch_resource_info($_params)) {
                    return false;
                }
                if ($_params['resource_timestamp'] <= filemtime($compile_path)) {
                    // template not expired, no recompile
                    return true;
                } else {
                    // compile template
                    return false;
                }
            }
        } else {
            // compiled template does not exist, or forced compile
            return false;
        }
    }


首先会看,是否设置了force_compile,如果为true,那么每次都要进行重新编译。
然后看是否要compile_check,如果为false,那么永远不会进行编译。
如果为true,那么进行检查,检查什么呢?检查文件的修改时间,如果编译结果的时间>=原模板文件的修改时间,那么不进行重新编译,否则进行编译。

关键在于这个“等号”,我们应该将这个“=”去掉呢?还是他真的有必要?

有事,待续...
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics