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

How to selected in select option using Tag

In view.phtml of edit news action, i want to show all categories of news ( such as healthy, sport, joke) and selected is correct which it has before. How to do this with Tag

echo Phalcon\Tag::select(array( "2", Menu::find("id != '0'"), "using" => array("id", "name"), ));

html correct like this:

<select> <option value="1">news</option> <option value="2" selected="selected">healthy</option> <option value="3">joke</option> </select>



2.8k
Accepted
answer

Something like this:

<?php

echo Phalcon\Tag::select(array(
    "robotId",
    Robots::find("type = 'mechanical'"),
    "using" => array("id", "name"),
    "value" => 1 // This is a setDefault() shortcut for tag call
    ));

"value" => 1 // This is a setDefault() shortcut for tag call

It works. Thank you so much. I have searched in forum but i can't find it.

Please mark this as solved, then.

This should be placed in documentation.