Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Smarty动态选择字段中的对象_Php_Smarty - Fatal编程技术网

Php Smarty动态选择字段中的对象

Php Smarty动态选择字段中的对象,php,smarty,Php,Smarty,我想创建一个选择下拉列表,其中填充了我放在数组中的Categories数组 $contents是一个数组,其条目在smarty中自动分配 foreach ($contents as $key => $value) { $this->_smarty->assign($key, $value); } Controller.php: private $contents; public function createStart() { $categories = $

我想创建一个选择下拉列表,其中填充了我放在数组中的Categories数组

$contents
是一个数组,其条目在smarty中自动分配

foreach ($contents as $key => $value) {
    $this->_smarty->assign($key, $value);
}
Controller.php:

private $contents;

public function createStart() {
    $categories = $service->listCategories();
    $this->contents['categories'] = $categories;

    return 'documentsform-view';
}
<select>
  {html_options options=$categories}
</select>
html视图:

private $contents;

public function createStart() {
    $categories = $service->listCategories();
    $this->contents['categories'] = $categories;

    return 'documentsform-view';
}
<select>
  {html_options options=$categories}
</select>

{html_options options=$categories}
这不管用


类别是对象。我希望我的选项值采用每个类别ID,并显示每个类别名称。我该怎么做

我用smarty
foreach解决了问题

<select>
  {foreach item=category from=$categories}
    {html_options values=$category->getId() output=$category->getName()}
  {/foreach}
</select>

{foreach item=category from=$categories}
{html_options values=$category->getId()输出=$category->getName()}
{/foreach}