Having A Problem Concating A String For Listdata

So here is my code, if I replace the 3rd param (’_sizes’) with one of the table columns, I will get that column. From what I understand this is how it is to be done but it’s just returning Null values.




        private $_sizes;

        public function showGroupSize()

        {

            $groupSizes = GroupSizes::model()->findAll();

            $list = CHtml::listData($groupSizes,'id', '_sizes');

            var_dump($list);

            return $list;

        }

        

        public function getSizes()

        {

                return $this->height.'x'.$this->width;

        }



It works if I use an anonymous function though.





        public function showGroupSize()

        {

            $groupSizes = GroupSizes::model()->findAll();

            $list = CHtml::listData($groupSizes,'id', function ($sizes){return $sizes->height.'x'.$sizes->width;});

            return $list;

        }

        

        public function getSizes()

        {

                return "'".$this->height.' x '.$this->width."'";

        }



Your first example should look like this:




$list = CHtml::listData($groupSizes,'id', 'sizes');



You don’t need the private variable.

have you tried:




$criteria = new CDbCriteria;

$criteria->select = 't.id, CONCAT(t.height,"x",t.width) as size'; // select fields which you want in output

$criteria->condition = 't.status = 1';


$data = Users::model()->findAll($criteria);


$list = CHtml::listData($data ,'id', 'size');