【问题标题】:smarty - function include_php set arrgument file from arraysmarty - 函数 include_php 从数组中设置参数文件
【发布时间】:2013-11-17 23:38:51
【问题描述】:

我需要在数组中包含 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) 中的路径:第 1 行的 eval() 代码

{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 作为数组键。

【问题讨论】:

    标签: php include smarty


    【解决方案1】:
    $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); 
    

    【讨论】:

    • 我更新了我的答案,smarty var assign 是正确的,我一直在使用它。我尝试更改对象的定义
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    • 2016-04-22
    • 2019-01-11
    • 1970-01-01
    • 2023-04-09
    • 2014-11-11
    相关资源
    最近更新 更多