0

我需要在数组中包含 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 - 这个抛出错误致命错误:未捕获的异常'SmartyCompilerException'与消息'模板中的语法错误......和注意:未定义的索引:/home/web/tools/smarty/sysplugins/smarty_internal_compile_include_php.php中的路径(61) : eval()'d 代码在第 1 行

{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

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

4

1 回答 1

0
$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); 
于 2013-11-06T16:27:50.477 回答