Select tag option use other field in Model

Hi, I want to build select tag option using field that is a combination of two fields in resultsets. I know if this can be code using "concatenate" when querying and get the resultset, but I want to achieve it by using Model only. I already created new setter/getter, but I cannot show it in Views. Below is my code:

Lets say we have Countries table: Countries have: Id, Code, and Name.


    class Countries extends Model{
        public $Id;
        public $Code;
        public $Name;
        public $CodeName;

        public function setCodeName()
            $this->CodeName = $this->Code . " - " . $this->Name;

        public function getCodeName()
            return $this->CodeName;


    $countries = Countries::find();

    /*I also use this but its still not work

    foreach($countries as $country){


    echo $this->tag->select(
            "using" => array('Id', 'CodeName'),
            "useEmpty" => true,
            "emptyText" => 'Please choose...',
            "emptyValue" => '0',
            "class" => "test",

And the result, it return empty in option selection. Please help.

Thank you.


Hi I am assuming that you have form:

    $results = Teacher::find(
            'columns' => 'Id, ' . new  RawValue('CONCAT (LastName, " ", FirstName) as typeName')

    $teacherParams = array(
        'useEmpty'  => true,
        'emptyText' => '-----',
        'using'     => array('Id', 'typeName')

    $TeacherId = new Select('TeacherId', $results, $teacherParams);

    $TeacherId->setLabel(_('Teacher Name'));
        new PresenceOf(array(
            'message' => (_('Teacher is required'))

And in view you can use following

                            <td>    {{form.label('TeacherId')}}     </td>
                            <td>    {{form.render('TeacherId')}}    </td>