Dinamic Model




<?


class dimamic()

{

   public $namemodel ; //Name the model  (User , Office , Category , Seccion....)


   function find($findString){


return $this->namemodel::model()->find($findString); // i have problem with the :: static ?

}




}




?>




Yii have any method , that i can call/get model ?

I am not pretty sure what you want to accomplish but I think you’ll have to write it this way:




<?


class DynamicModel

{

   public $name ; //Name of the model  (User , Office , Category , Seccion....)


   public function find($findString)

   {

       $class=$this->name;

       return $class::model()->find($findString);

   }




}




?>




here’s part of my MgActiveRecord which introduces some general routines:





<?php

/**

 * Base class for ActiveRecord models

 * @author Michal migajek Gajek

 * @copyright 2011 Michal Gajek

 * @package mg.core

 */

abstract class MgActiveRecord extends CActiveRecord 

{

	/**

	 * create CActiveDataProvider for currently applied scopes (criteria)

	 * @return CActiveDataProvider

	 */

	public function findScopedAll($pageSize = 20)

	{

		return new CActiveDataProvider(get_class($this), array(

			    'criteria'=> $this->getDbCriteria(),

			    'pagination'=> array(

			        	'pageSize'=> $pageSize,

			        	'pageVar' => 'page' 

			    	),

			));		

	}

	

	

}

basically, I use get_class($this) instead of defining model name.

thus, each model should extend above class.

Is bad way ? Sorry i don´t know english very well … (i am spain)

Thx and Sorry.