PHP与命名空间和Smarty错误:未知标签“循环”
Everyone!
I'm working with PHP and Smarty in my project. I'm using namespaces and I'm having a problem when I call Smarty functions, for sample cycle
I'm having this error: Syntax Error in template ".\sys\adm\template\fields\inputFileField.tpl" on line 23 "{cycle values="um,dois"}" unknown tag "cycle"
I'm using spl_autoload_register to auto load classes in project:
function smartyAutoloader($className) {
$file = "sys/classes/smarty/$className.class.php";
if (file_exists($file)) {
require $file;
return true;
}
return false;
}
I did not change the namespace in Smarty class, so I'm importing Smarty this way:
use \Smarty;
If I comment the cycle code, my code works correctly.
Follow is the problemmatic code:
{for $x = 0 to 10}
{cycle values="um,dois"} {*line 23 on inputFileField.tpl*}
{/for}
I'm not knowing to use namespace and Smarty in same project. I'm sure this error is because of namespaces. Can someone help me?
Thanks in advance
所有人! p>
我在我的项目中使用PHP和Smarty 。
我正在使用名称空间,当我调用Smarty函数时遇到问题,样本循环 strong> p>
我遇到此错误:第23行模板“。\ sys \ adm \ template \ fields \ inputFileField.tpl”中的语法错误“{cycle values =”um,dois“}”unknown tag“cycle” strong> p>
我正在使用spl_autoload_register在项目中自动加载类: p>
我没有更改Smarty类中的命名空间,因此我以这种方式导入Smarty: p>
如果我对循环 strong>代码发表评论,我的代码可以正常运行。 p>
关注是问题 代码: p>
提前致谢 p>
div>
function smartyAutoloader($ className){
$ file =“sys / classes / smarty / $ className.class.php“;
if(file_exists($ file)){
需要$ file;
返回true;
}
返回false;
}
code > pre>
use \ Smarty; \ n code> pre>
{为 $ x = 0到10}
{周期值=“um,dois”} {*第23行在inputFileField.tpl *}
{/ for}
code> pre>
我不知道在同一个项目中使用名称空间和Smarty。 我确定这个错误是因为名称空间。
是否有人帮助我? strong> em> p>
I found this post at the Smarty forum
The problem seems to be a wrong or relative path to the plugin folder. After setting the path to the plugin folder absolut, it works fine, even with namespaces.
Have also a look at the Smarty documentation:
Technical Note
For best performance, do not setup your
$plugins_dir
to have to use the PHP include path. Use an absolute pathname, or a path relative toSMARTY_DIR
or the current working directory.
You have to set setPluginsDir like this:
$dirSep = DIRECTORY_SEPARATOR;
$path = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR;
$smarty->setPluginsDir($path."smarty".$dirSep."libs".$dirSep."plugins");