`
xombat
  • 浏览: 162555 次
  • 性别: Icon_minigender_1
  • 来自: 乌托邦
社区版块
存档分类
最新评论

smarty什么时候会从新编译template

阅读更多
从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