Another model of same type of given object

I have a model in a variable: $model. I want to get another model of a same type. How do I do that if I don’t know what class is the $model variable?


$newModel = new get_class($model);

Above doesn’t work – it attempts to include get_class.php.

Try this:


$className=get_class($model);

$newModel=new $className;

You can also use the class in a static way like this:




CActiveRecord::model(get_class($model))->findAll();