Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Model getters in Volt helper tags.

I have a Model named Employees:

<?php
class Employees extends \Phalcon\Mvc\Model {
    public $first_name;
    public $last_name;

    public function columnMap() {
        return array(
            'first_name' => 'first_name', 
            'last_name' => 'last_name'
        );
    }

    public function getFullName() {
        return $this->first_name . ' ' . $this->last_name;
    }
}

Now I want to create a select input that shows the employee's full name:

{{ select("employees[]", employees, 'using': ['id', 'getFullName']) }}

I also tired &#039;using&#039;: [&#039;id&#039;, &#039;first_name&#039; ~ &#039;last_name&#039;], but it also displays nothing.



5.8k
Accepted
answer
edited Mar '15

I'm unsure about the full extensibility of the select tag helper in volt, but I don't think using model methods as an attribute would work.

The cleanest way would be to extend volt yourself, and create a function that could handle passing through a model method, rather than relying on string interpreted properties.

Extending Volt

or if you're just after quick/easy, it might be best to create the full HTML yourself, something like:

<select name="employees[]">
{% for employee in employees %}
    <option value="{{ employee.id }}">{{ employee.getFullName() }}</option>
{% endfor %}
</select>