2017-04-17 85 views
0

创建了一个简单的Smarty插件与下面的代码错误同时呼吁从TPL文件中的智者插件功能

/* 
* Smarty plugin 
* ------------------------------------------------------------- 
* File:  function.assignmenu.php 
* Type:  function 
* Name:  assign 
* Purpose: assign a value to a template variable 
* ------------------------------------------------------------- 
*/ 
functionality-to-smarty-w-plugins/ 

function smarty_function_assignmenu(Smarty_Internal_Template $smarty) 
{ 
    //$template->assign($params['var'], $params['value']); 
    $smarty->assign('test', '123'); 
} 

而这个功能从模板文件称为 {assignmenu} {测试}

虽然访问该页面时,将返回以下错误 传递给smarty_function_assignmenu()的参数1必须是Smarty_Internal_Template的实例,该实例在/var/www/myproject/runtime/Smarty/compile/cda404646b2153274a9e77f736531c5dc7e6f91c_0.file.sample.tpl中给出第31行的.php和d efined

我正在用yii2使用smarty 3。任何帮助表示赞赏

回答

0

Smarty插件函数期望一个数组作为第一个参数。因此,定义应该是

function smarty_function_assignmenu($paramArray,Smarty_Internal_Template $smarty) 
{ 

    $smarty->assign('test', '123'); 
} 

即使没有参数传递,函数定义应包含数组作为第一个参数。

相关问题