Getting Any Model Class


I’m developing a new template for crud form. The current class model is always acessed by $this->modelClass on this form. At some point i needed to use another model to generate a dropbox using data istead of just showing the foreign key. How can i get another model within this context, here goes the code:

foreach($this->tableSchema->columns as $column)





if($column->isForeignKey) {


<div class="row">

	<?php echo "<?php echo ".$this->generateActiveLabel($this->modelClass,$column)."; ?>\n"; ?>

	<?php echo "<?php echo CHtml::activeDropDownList(\$model,'{$column->name}', CHtml::listData(".

            [color="#FF0000"]$this->modelClass[/color]."::model()->findAll(), '{$column->name}', 'Nome')); ?>\n"; ?>

	<?php echo "<?php echo \$form->error(\$model,'{$column->name}'); echo CHtml::link('New', 'index.php?r=".strtolower(str_replace(array('id','_'),'',"{$column->name}"))."', array('target'=>'_blank'));"; ?> ?>


[color="#FF0000"]$this->modelClass[/color] should be replaced with another model i choose, how do i get another model? anything would help, getting by its name, by database’s table name… etc


I have the same problem… if you found any solution please share it with me.

There are some gii related extensions that deal with the relations of the model.

For example, ‘gii-template-collection’ and ‘giix’. They will come up with a dropDownList when the target column is a foreign key of a BELONGS_TO relation.

I think you can use one of them out of the box, or read the source codes of them to learn how to do it.

The links to those resources are:

Gii Template Collection

On Yii:

On Google Code:


On Yii:

On Google Code:

Hi to all:

The problem is solved with the function call_user_func() of PHP. I test with metaclass, factory pattern and other but nothing work. I hope that Peter Thorun can solve his problem too. Here you have a piece of code:

<div class="row">


$modelTemp = call_user_func($className.'::model'); 

echo $form->dropDownList($model, {$column->id}, CHtml::listData($modelTemp->findAll(), '{$column->id}', '{$column->name}'),array('prompt'=>Yii::t('NameNodule.tfile', '{$column->promptMsg}'),));

// ... the rest of code lines...



I will try the solution of softark. Thanks.

Best regards.