We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

select on phalcon

how to show just one on select...

Screenshot

sory for bad languange

edited Dec '17
// Here Categories is some model
$categories = Categories::find([
    'conditions' => 'number_posts BETWEEN ?1 AND ?2',
    'order'      => 'name DESC',
    'limit'      => 10,
    'bind'       => [
        1 => 8,
        2 => 12,
    ],
]);

$select = Phalcon\Tag::select(
    [
        'category',
        $categories,
        'name'      => 'categories',
        'emptyText' => 'Choose category ...',
        'useEmpty'  => true,
        'using'     => [
            'id',
            'name'
        ],
    ]
);

echo $select;

This code will generate such HTML:

<select id="category" name="categories">
    <option value="">Choose category ...</option>
    <option value="31">Wilkinson and Sons</option>
    <option value="35">Upton-Hyatt</option>
    <option value="24">Strosin-Will</option>
    <option value="28">Simonis-Stracke</option>
    <option value="7">Rice, Breitenberg and Upton</option>
    <option value="10">Renner-Waters</option>
    <option value="11">Rempel, Hodkiewicz and Quitzon</option>
    <option value="22">O'Keefe-Block</option>
    <option value="2">Marvin, Schoen and Pagac</option>
    <option value="43">Keebler, Rosenbaum and Kessler</option>
</select>
edited Dec '17
public function createAction()
{
    # code...
    $this->view->menu = Menu::find();
}

volt

<div class="form-line">
    {{ select(
        "parent_id",
        menu,
        "using" : ['id_menu','menu'],
        'useEmpty' : true,
        'emptyText' : 'Please Select...'
    ) }}
</div>

im beginer on this framework...