Hi,
I want to add options to my form's select field using addOption() method. Docs state that it takes an array as an argument, well in my case it does not. I'm using Phalcon 1.2.3 and I'm sure I'm doing something wrong, but I don't really know what. What I want to achieve is pass an id and a value, which consists of a given text (in my case "(role_type) role_name", however the only thing I get in the view is the string 'Array'. addOption() method works fine with a string. In my form class I set the select field as follows:
$user_role_params = array(
'useEmpty' => true,
'emptyText' => 'Please Select...',
'using' => array('id', 'name')
);
$acl_roles = Role::find();
$user_role = new Select('role_id');
$user_role->setAttributes($user_role_params);
foreach ($acl_roles as $acl_role) {
$user_role->addOption(array(
'id' => $acl_role->getId(),
'name' => '('.$acl_role->getType().')'.$acl_role->getName()));
}
$user_role->setLabel('User Role: ');
$this->add($user_role);
And my view is a simple volt template with the following content:
<form method="post">
{% for field in form %}
<p>
{% set label = field.getLabel() %}
{% if label !== '' %}
<label for="{{ field.getName() }}">{{ label }}</label>
{% endif %}
{{ field }}
</p>
{% endfor %}
{{ submit_button("Add User") }}
</form>
Thanks.