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

Injecting value in a select list


I create a select list with an UI Element like INVO :

The code :

class Elements extends Phalcon\Mvc\User\Component {

public function getUserStatusDropdown() {

    $translate = $this->di->get('translate');

    $select = "<select class='form-control' id='IsBlocked' name='IsBlocked'>
                <option value='-1'>" . $translate->_('Select') . "</option>
                <option value='0'>" . $translate->_('Enabled') . "</option>
                <option value='1'>" . $translate->_('Disabled') . "</option>

    echo $select;


In my view : {{ elements.getUserStatusDropdown() }}

And in my controller, I set all the form data including the select list:

This is what I've try so far :

$this->tag->setDefaults(array('IsBlocked' => $user->IsBlocked)); $this->tag->setDefaults(['IsBlocked' => [$user->IsBlocked]]);

but none of them works, I can't have the option selected.

Any suggestion ?


have you registered 'tag' in DI? Why not call it's static method Phalcon\Tag::setDefaults() ?


Hi, no need to register tag in DI. The tag is available in the controller by inheritance.

Only the one for the select list doesn't works :

        $this->tag->setDefault("ID", $User->ID);
        $this->tag->setDefault("AddressID", $User->AddressID);
        $this->tag->setDefault("Email", $User->Email);
        $this->tag->setDefault("Firstname", $User->Firstname);
        $this->tag->setDefault("Lastname", $User->Lastname);
        $this->tag->setDefaults(array('IsBlocked' => $User->IsBlocked)); <------------Not working
        $this->tag->setDefault("Password", $User->Password);
        $this->tag->setDefault("Type", $User->Type);
        $this->tag->setDefault("MainPhone", Format::phone($User->MainPhone));
        $this->tag->setDefault("OtherPhone", Format::phone($User->OtherPhone));


I manage to fix this issue by using a model class for the data in the list.

This can be closed now.