Yii Framework Forum: Cgrid View Model Search With One To Many Values - Yii Framework Forum

Jump to content

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

Cgrid View Model Search With One To Many Values Creating a model depending on 1toMany for getting it in the cgridview Rate Topic: -----

#1 User is offline   VeeTee 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 17-November 12

Posted 17 November 2012 - 09:10 AM

Hi guys,

Like a lot of you, I'm pretty new to Yii and I have a question.
I can make models, show records in cgridview and search the records even for 1to1 relations with other tables...
Now I need a good solution for A 1 to Many...

let's say I have 3 tables...
Clients
Clientpropertyvalues
Clientpropertynames...

Clients
-id (pk)
-username
-password
-updated
-active

clientpropertynames
-id (pk)
-name

clientpropertyvalues
-id (pk)
-clientid (Fk -> clients.id)
-propertynameid(FK -> clientpropertnames.id)
-value

so for data we has
CLIENT
1 | user1_username | user1_password | 2012-11-17 ... | 1
2 | user2_username | user2_password | 2012-11-17 ... | 1

CLIENTPROPERTYNAMES
1 | name
2 | last name
3 | street
4 | nr
5 | city
6 | zip
7 | email
....

CLIENTPROPERTYVALUES
1 | 1 | 1 | Tom
2 | 1 | 2 | Peeters
3 | 1 | 3 | straatnaam
4 | 1 | 4 | 3
5 | 1 | 5 | Antwerpen
6 | 1 | 6 | 2000
7 | 2 | 1 | Tommy
8 | 2 | 2 | Seghers
9 | 2 | 3 | straatnaam
10 | 2 | 4 | 5
11 | 2 | 5 | Brussel
12 | 2 | 6 | 1000


how can I implement this in a Yii model so I can have a provider for the gridview to view and search in with data like this

id | username | password | active | name | lastname | street | ....
1 | user1_username | user1_password | 1 | tom | peeters | straatnaam |
1 | user2_username | user2_password | 1 | tommy | seghers | straatnaam |


How do I create my model(s)
how can I get the data together for the gridview ?
and how can I implement the filter search ???


thanks for helping...
0

#2 User is offline   Kostas Apazidis (KonApaz) 

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

Posted 17 November 2012 - 02:48 PM

Hi VeeTee

The best way for this, is to have 3 seperated models with relations

check for it in
http://www.yiiframew...en/database.arr

models data together and search in gridview see below link
http://www.yiiframew...ls-in-gridview/
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
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