speedphp+smarty开发 怎么开启smarty中执行PHP代码

#1 xiaobai

<{php}>
echo "现实内容";
<{/php}>

报错为
Smarty Error: {php} is deprecated, set allow_php_tag = true to enable
网上搜了下
$smarty->allow_php_templates = true; 这玩意不知道在哪里添加 高手麻烦指点下,


2012-02-12 22:58:20

#2 jake

在控制器内

$this->getView()->allow_php_templates = true;

2012-02-13 09:01:55

#3 xiaobai

jake 发表于 2012-2-13 09:01
在控制器内

$this->getView()->allow_php_templates = true;
谢谢 应该是这个。$this->getView()->allow_php_tag = true;

2012-02-13 15:25:46

#4 jake

本帖子应该发到求助问答区的,以后麻烦注意一下。

本帖稍候将转移!

2012-02-13 16:43:36

#5 竹叶青

你好 我使用smarty的时候,默认使用它的分界符号是{ },在我的模版文件中代码是



    {php}
        echo "hehe";
    {/php}



我在php运行文件中代码是
    require('smarty_connect.php');
    $smarty = new smarty_connect;
   
    $smarty->assign('name','he');
    $smarty->display('index.html');

?>

但是运行这个php文件却编译错误,错误信息为
Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "D:/EclipseWorkspace/test/Smarty/templates\index.html" on line 4 "{php}" unknown tag "php"' in F:\xampp\Smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php:627 Stack trace: 0 F:\xampp\Smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php(406): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "ph...', 4) 1 F:\xampp\Smarty\libs\sysplugins\smarty_internal_templateparser.php(2418): Smarty_Internal_TemplateCompilerBase->compileTag('php', Array) 2 F:\xampp\Smarty\libs\sysplugins\smarty_internal_templateparser.php(3111): Smarty_Internal_Templateparser->yy_r37() 3 F:\xampp\Smarty\libs\sysplugins\smarty_internal_templateparser.php(3211): Smarty_Internal_Templateparser->yy_reduce(37) 4 F:\xampp\Smarty\libs\sysplugins\smarty_internal_smartytemplatecompiler.php(105): Smarty_Internal_Templateparser->doParse(10, '????echo "hehe"...') 5 F:\xampp\Smarty\libs\sysplugins\smarty_internal_temp in F:\xampp\Smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php on line 627

提示无法识别php符号 这是为什么啊 我已经开启了$this->allow_php_templates = true;  
谢谢

2012-03-29 09:17:58

#6 jiujiu

怀疑是这个

2012-03-29 12:25:39

#7 jake

两步,首先去掉{php}{/php}部分,搞好左右限定符,是{}还是先能够执行了。

然后加入{php}{/php}那么就知道是什么问题了。

还有,提醒一下,不要对smarty内的{php}抱太大希望,那个php标签里面的代码和真正的PHP差距很大,有很多功能都用不了的。如果要实现什么复杂的功能,建议看看手册里面的“注册函数”更好。

2012-03-29 20:05:12