Hello !
I have a question,
on my page I have list of categories , it’s just name of category and it is a link to category page, when you click link then you go to category page and see full category info.
In order to display category menu list I created simple widget which gets data about categories in this way:
$categoryData = Yii::app()->db->createCommand()
->select('category_id,parent_category_id, name')
->from('categories c')
....
->queryAll();
This returns me a simple array which contains only data I need, no unnecessary fields.
in widget view file I display these categories and I also need to create a link to it, here is where I have problem now. As I undertstand the best way is to create a method getUrl in the model class and use it everywhere, but in my case it will not work because list of categories is simple array with category_id,parent_category_id, name properties. If I want to use getUrl I need do that each category item is an object of Category model so I can use getUrl method, so I need to get categories list in this way:
$categoryData= Category::model()->with('transMenu')->findAll()
but I don’t want use this findAll because it will create a big object for each category item with ALL fields (it has 45 fields) I have in category table, that is what I don’t like as we ask database for a lot of unnecesarry info which is not need. This category menu is displayed on every page so I want to make it work very fast.
is there a way so I use simple ->queryAll() way and use getUrl function for both model and not model cases ?