我的表格中包含id
name
和status
的标签,我的模型TagsStandard
中有这样的标签:
const STATUS_APPROVED = 1;
const STATUS_DISABLED= 0;
public $id;
public $name;
public $status;
public static function getAllTag()
{
$tags = TagsStandard::find(array(
"status = 'STATUS_APPROVED'",
"order" => "id"
));
}
所以我得到了所有的标签。现在在indexAction
的控制器中我有:
$tags = TagsStandard::getAllTag();
if ($tags) {
$this->view->tags = $tags;
$this->view->name = array("name" => $tags->name->toArray());
}
在索引中我有:
<select id='user-skills-input' class="select-chosen" type="text" data-role="tagsinput" value="" multiple>
<?php if(count($tags) > 0): ?>
<?php foreach($tags->items as $idx => $tag):
echo "<option value='" . $tag->id . "'> " . $tag->name . "</option>" ?>
<?php endforeach; ?>
<?php endif; ?>
</select>
这些值没有出现在选项中,所以任何人都可以帮我解决这个问题吗?
答案 0 :(得分:2)
<?php
echo \Phalcon\Tag::select(array(
"user-skills-input",
TagsStandard::find(array(
"status = 'STATUS_APPROVED'",
"order" => "id"
)),
"using" => array("id", "name")
);