Hi,
I have a single table of pages. Pages can be of different types. Not all
types share the same fields or validation rules so I have a different model
for each type. What I want is to get an array of models according to the
type of page when performing CActiveRecord::find() or similar function.
Is this possible?
twisted1919
(Serban Cristian)
2
I don’t believe your approach is correct.
Therefore, this is how i think you should do it:
Create a single model for your table and differentiate the content types with a WHERE type=? condition in AR:
->find('type=:t',array(':t'=>'article'));
This will help you retrieve the records based on their types.
For saving/updating data in the model use scenarios.
If a content type requires certain fields, just create a scenario for those fields.
Take a look at the scenarios usage in the documentation for more info.
tolaipner
(Laiskas)
4
Thank you, that’s exactly what I was searching for. I have considered
using twisted1919’s approach, but the model becomes vary complex when
there are many types of pages and it’s a lot harder to add new types.