Yii Framework Forum: select tableName in model according to logic - Yii Framework Forum

Jump to content

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

select tableName in model according to logic the latest Yii 1.1 Rate Topic: -----

#1 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 747
  • Joined: 02-February 09

Posted 05 January 2010 - 11:36 AM

Hi,

Instead of having a model for each of my tables I would like to have one model for all tables and to be able to switch between tableName according to a GET parameter. What would be the best way to do that and how to do it in a way that Yii first validates the GET parameter.

Example:
A request with ?id=someparam => logic should load table Param.
?id=someparam2 => logic should load table Param2

I guess I can try doing it with if...else... but if someone knows a better way please share :)

Best,
b
0

#2 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 747
  • Joined: 02-February 09

Posted 06 January 2010 - 05:07 AM

I guess this is not a viable option. I should rather have a model for each table and then create a logic in one controller to switch between models to select tables....as my tables have different metadata.
0

#3 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 06 January 2010 - 05:24 AM

A model represents a table in a database. But if your models have something common, then create a child of CModel (or CActiveRecord) with all common properties and methods, and then use this model as a parent for your models.
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