Yii Framework Forum: How To Create Cgridview With Three Models - Yii Framework Forum

Jump to content

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

How To Create Cgridview With Three Models Rate Topic: -----

#1 User is offline   Gasim 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 14-June 11

Posted 21 July 2013 - 02:37 AM

Hello,
I am having trouble trying to build a CGridView table in Yii with three models. Here is the scenario:

Table: Products
prod_id, prod_name
HAS_MANY -> Prices

Table: Regions
reg_id, reg_name
HAS_MANY -> Prices

Table: Prices
price_id, prod_id, reg_id, price
BELONGS_TO -> Products
BELONGS_TO -> Prices


Products/Regions | Region#1 | Region#2 | ... | Region#N
--------------------------------------------------------
Product#1        | Price#1  | Price#2  | ... | Price#N
Product#2        | Price#1  | Price#2  | ... | Price#N
Product#3        | Price#1  | Price#2  | ... | Price#N
...
Product#N        | Price#1  | Price#2  | ... | Price#N


I have all the relations and ActiveRecords set up for this. I know I can create this GridView in a non Yii way. But i want to know if there is a way to do this with CGridView because i need to have filters, pagination and sorting in this situation.

Thanks,
Gasim
Sincerely,
Gasim Gasimzada
0

#2 User is online   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,324
  • Joined: 21-February 11
  • Location:Greece

Posted 21 July 2013 - 03:45 AM

Hi

check this wiki that referred το multiple same models
http://www.yiiframew...-one-cgridview/

you have to modify some code to union the fields
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   Gasim 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 14-June 11

Posted 21 July 2013 - 04:53 AM

View PostKonApaz, on 21 July 2013 - 03:45 AM, said:

Hi

check this wiki that referred το multiple same models
http://www.yiiframew...-one-cgridview/

you have to modify some code to union the fields


This is a good idea but how am i really supposed to approach my problem using this. Lets say, I am starting from Prices because the prices have access to both stores and products. Lets say we know that usually the number regions are way less than the number of products. So as an example, I have 20 products and 5 regions. Am i going to have 5 activedataproviders (1 per region)? How efficient is it relative to plain SQL. I know activerecord is usually slower than plain sql query but in my scenario it sounds like an overhead, isnt it? Im going to give it a shot and do couple tests to see how it is.

Thanks,
Gasim
Sincerely,
Gasim Gasimzada
0

#4 User is online   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,324
  • Joined: 21-February 11
  • Location:Greece

Posted 21 July 2013 - 09:49 AM

View PostGasim, on 21 July 2013 - 04:53 AM, said:

This is a good idea but how am i really supposed to approach my problem using this. Lets say, I am starting from Prices because the prices have access to both stores and products. Lets say we know that usually the number regions are way less than the number of products. So as an example, I have 20 products and 5 regions. Am i going to have 5 activedataproviders (1 per region)? How efficient is it relative to plain SQL. I know activerecord is usually slower than plain sql query but in my scenario it sounds like an overhead, isnt it? Im going to give it a shot and do couple tests to see how it is.

Thanks,
Gasim


try something like that:

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        'field1',
        'field2',
        'field3',
        array('name'=>'extrafield1',               
               'value'=> '$data->Regions[0]->Prices->price')
        )
        array('name'=>'extrafield2',               
               'value'=> '$data->Regions[1]->Prices->price')
        )
        ...

    )
);

Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
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