天天看点

从smarty文件结构部署看面向对象中路径的作用域

①上边的代码是Smarty类的构造函数源代码,所在文件是:E:\APMServ\www\htdocs\zf\two\smarty\Smarty.class.php

②我在另一个文件中(ZF的入口文件中)将该文件包含进来:E:\APMServ\www\htdocs\zf\two\index.php

③我在第三个文件中使用这个new出来的对象:E:\APMServ\www\htdocs\zf\two\application\controllers\HelloController.php

问题是:①中smarty的构造函数默认的templates和templates_c等等文件应该和smarty.class.php在同一文件夹下,那么我在②中new这个类生成对象,③文件中使用这个对象,那我到底应该把templates和templates_c等等文件夹建在那里呢

结果:应该与new这个类的语句所在的文件建在同级目录下,否则会出现:

SmartyException: Unable to load template file

'hello.phtml' in

E:\APMServ\www\htdocs\zf\two\smarty\sysplugins\smarty_internal_templatebase.php

当然你没有用smarty默认的路径,而是另外指定的路径,那就看你指定到哪里了