聪明 - 从数组include_php设置文件的功能


smarty - function include_php set arrgument file from array

我需要在数组中包含php和文件路径。

控制器

$object[0]['id'] = 1;
$object[0]['path'] = '/home/path/for/file/file.php';
$static_path[0] =  '/home/path/for/file/static_path.php'; 
$this->smarty->assign(array(
'object' =>     $object,
'static_path' =>    $static_path
)); 

在 .tpl 中 - 此抛出错误 致命错误:未捕获的异常"Smarty编译器异常",消息为"模板中的语法错误...和注意:未定义的索引:/home/web/tools/smarty/sysplugins/smarty_internal_compile_include_php.php(61) 中的路径:第 1 行的 eval()'d 代码

{foreach from=$object item=value}
 {include_php file=$value['path']} // trhow error msg
 {$value['path']} // this show string path correctly
{/foreach}

在 .tpl 中 - 这没问题

 {include_php file=$static_path[0]} //incude correctly

我想使用每个我需要使用var作为数组键。

$object = array(
  array(
    'id' => 1,
    'path' => '/home/path/for/file/file.php'
  )
);
// I'm not sure about this
$this->smarty->assign(array(
  'object' => $object
));
// May be the coorect way is, depending on template
$this->smarty->assign('object' => $object);