Yii Framework Forum: using model getUrl function from not a model - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

using model getUrl function from not a model Model, getUrl Rate Topic: -----

#1 User is offline   dave101ua 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 23-April 12

Posted 18 May 2012 - 03:49 AM

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 ?
Yii newbie
0

#2 User is offline   saegeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 244
  • Joined: 09-December 09
  • Location:Montpellier - France

Posted 18 May 2012 - 04:04 AM

View Postdave101ua, on 18 May 2012 - 03:49 AM, said:

This category menu is displayed on every page so I want to make it work very fast.


How about to store the category menu into a temporary cache file ?
And [for] their saying, "Indeed, we have killed the Messiah, Jesus, the son of Mary, the messenger of God ." And they did not kill him, nor did they crucify him; but [another] was made to resemble him to them. And indeed, those who differ over it are in doubt about it. They have no knowledge of it except the following of assumption. And they did not kill him, for certain.Rather, God raised him to Himself.
0

#3 User is offline   dave101ua 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 23-April 12

Posted 21 May 2012 - 10:12 AM

View Postsaegeek, on 18 May 2012 - 04:04 AM, said:

How about to store the category menu into a temporary cache file ?

if there are no variants thant it's the only way...((
Yii newbie
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users