Dinamic model creation

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 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 :)

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?

I would choose (1) as it intuitively seems faster than (2). But it’s too late (~3 am in Germany) to think about that ;D

The Yii core uses the first method

to jonah

OK, then i’ll use first method in extensions too.