代码之家  ›  专栏  ›  技术社区  ›  Winston Chen

如何检测smarty模板框架的使用?

  •  0
  • Winston Chen  · 技术社区  · 15 年前

    3 回复  |  直到 15 年前
        1
  •  3
  •   pinaki    15 年前

    通常,结构良好的项目会有一个template和template\ c文件夹-尽管名称可以配置/更改。另外,在这些文件夹中查找.tpl文件。

    我看到的最好的方法是grep常见的smarty函数,比如fetch/assign/display,或者常见的smarty标记,比如{foreach}、{assign}、{if},等等。

        2
  •  2
  •   NatalieL    15 年前

    您可能需要四处寻找模板和模板\u c-在我的一个项目中,它们甚至不在htdocs中-smarty文件夹与htdocs处于同一级别。我们根据这个项目命名了Smarty类,所以即使是寻找“new Smarty()”也不起作用。

        3
  •  1
  •   Young    15 年前

    我想你可以通过检查基本视图类来解决这个问题

    class View
    {
        protected $tpl;
        protected $tplfilename;
    
        public function __construct()
        {
            $this->tpl = new Smarty();
    
            $this->tpl->template_dir = dirname(__FILE__)."/templates"; 
            $this->tpl->compile_dir = dirname(__FILE__)."/templates_c"; 
            $this->tpl->config_dir = dirname(__FILE__)."/configs"; 
            $this->tpl->cache_dir = dirname(__FILE__)."/cache"; 
            $this->tpl->left_delimiter = "{|";
            $this->tpl->right_delimiter = "|}";
    
            $this->tplfilename = "default.tpl";
        }
    
        public function show()
        {
            $this->tpl->display($this->tplfilename);
        }
    }
    

    这应该是一个典型的聪明风格。