Let's $modelClass='Post';
1) $model=CActiveRecord::model($modelClass)->findByPk(1);
2) $model=call_user_func(array($modelClass,'model'))->findByPk(1);
CActiveRecord is abstract class. Right choose is 2? Am I right or there is some other variant?
Page 1 of 1
Dinamic model creation How right?
#2
Posted 18 February 2010 - 08:23 PM
creocoder, on 18 February 2010 - 08:17 PM, said:
Let's $modelClass='Post';
1) $model=CActiveRecord::model($modelClass)->findByPk(1);
2) $model=call_user_func(array($modelClass,'model'))->findByPk(1);
CActiveRecord is abstract class. Right choose is 2? Am I right or there is some other variant?
1) $model=CActiveRecord::model($modelClass)->findByPk(1);
2) $model=call_user_func(array($modelClass,'model'))->findByPk(1);
CActiveRecord is abstract class. Right choose is 2? Am I right or there is some other variant?
1 will work properly,
2 will also work
Was that your question or did you try to ask something else?
// Edit: Ah, wait, you said:
"CActiveRecord is abstract class."
That's right, but abstract means that you cannot instantiate it - and you don't need to when calling a static method
Utinam ea res tibi usui fuerit!
#3
Posted 18 February 2010 - 08:41 PM
Quote
but abstract means that you cannot instantiate it - and you don't need to when calling a static method 
Yes, you're right. And yet 1 a bit faster and it's shorter
to Daniel M
And so, your own choose: 1 or 2?
No good, no bad, only consequence.
#4
Posted 18 February 2010 - 08:46 PM
I would choose (1) as it intuitively seems faster than (2). But it's too late (~3 am in Germany) to think about that
Utinam ea res tibi usui fuerit!
#5
Posted 18 February 2010 - 09:24 PM
The Yii core uses the first method
http://php-thoughts.cubedwater.com - my bloggings about Yii
#6
Posted 18 February 2010 - 10:34 PM
to jonah
OK, then i'll use first method in extensions too.
OK, then i'll use first method in extensions too.
No good, no bad, only consequence.
Share this topic:
Page 1 of 1

Help













