Php Smarty动态选择字段中的对象
我想创建一个选择下拉列表,其中填充了我放在数组中的Categories数组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 = $
$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}