如何从phalcon中的表中填充选择选项?

时间:2015-07-16 14:05:37

标签: php html phalcon

我的表格中包含id namestatus的标签,我的模型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>

这些值没有出现在选项中,所以任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

<?php
echo \Phalcon\Tag::select(array(
    "user-skills-input",
    TagsStandard::find(array(
        "status = 'STATUS_APPROVED'",
        "order" => "id"
    )),
    "using" => array("id", "name")
    );

Phalcon Tags#select