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

Multiple fields order and using in phalcon\tag select

How i do in phalcon\tag select to using multiple fileds and order by multiple fields in form's


                                    <?php
                                    echo Phalcon\Tag::select(
                                        array(
                                            "person_id",
                                            Persons::find(array("order"=>"surname","name")),
                                                "using" => array("id", "surname","name"),
                                                "class" => "form-control input-medium",
                                                "useEmpty" => true,
                                                "emptyText" => 'Person...'
                                        )
                                    );
                                    ?>

Thanks in advance



2.0k

There is 2 way:

  1. If u use surname and name concatenated in multiple place, than u can create a getter in ur model e.g:
getFullname() {
    return $this->surname.' '.$this->name;
}

and than "using" => array("id","fullname")

  1. if u use it just in here: than:
echo Phalcon\Tag::select(
                                        array(
                                            "person_id",
                                            Persons::find(array("order"=>"surname","name","columns"=>"concat(surname,' ',name) as fullname")),
                                                "using" => array("id", "fullname"),
                                                "class" => "form-control input-medium",
                                                "useEmpty" => true,
                                                "emptyText" => 'Person...'
                                        )
                                    );


16.3k
Accepted
answer
edited Jul '14

I too have this issue. I tried your solutions, didn't work for me. I am trying to show multiple columns concatenated in the drop down list. The first one doesn't fill the column data, i.e. nothing appears in fullname equivalent in my script. I am also not sure if the case of field matters in getter. I tried all combinations like getOccupationDetail, getOccupationdetail etc and all lowercase in "using" clause.

In second approach I keep getting error below where ab_occupation_iid is my select column which is an integer. It works fine if I remove the whole condition in find clause.

PHP Notice:  Undefined property: Phalcon\Mvc\Model\Row::$ab_occupation_iid in C:\Wamp\www\ciab\app\views\company\create.volt.php on line 56

My Code in the Form file looks like below:

$this->add(new Select("ab_occupation_iid", Occupation::find(array("columns"=>"concat(ab_main_category_id, ", ", ab_category_id, ", ", ab_occupation_title) as ab_occupation_detail")), array( "using" => array("ab_occupation_iid", "ab_occupation_detail"),....

I would appreciate any hints or detailed example. Thanks.



7.4k
edited Jul '14
  1. it's working for me.
<?php
                        echo Phalcon\Tag::select(
                            array(
                                'produccion_id',
                                Producciones::find(array(
                                            'order'=>'code', 
                                            'columns'=> array('id', " CONCAT(code, ' ', name) as codename"),
                                            )),
                                    'using' => array('id', 'codename'),
                                    'class' => 'form-control input-medium',
                                    'emptyText' => 'Produccion...'
                            )
                        );

I Think you need to define id in columns array to work.