Yii Framework Forum: Model() Static Method Implementation For Cmodel? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Model() Static Method Implementation For Cmodel? The CActiveRecord static method model() would be useful in CModel Rate Topic: -----

#1 User is offline   MaxPowers 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 11-November 12

Posted 12 December 2012 - 07:43 PM

I have been forced to replace the usage of CActiveRecord with CModel (and DAO) because I am connecting to Sybase, for which I haven't the time to write a schema driver for.

Anyways, as I have been modifying my previously working code (originally used MySQL), I noticed how useful the static method model() CActiveRecord offers is. Why isn't there a similar static method for CModel?

/**
* Returns the static model of the specified AR class.
* The model returned is a static instance of the AR class.
* It is provided for invoking class-level methods (something similar to static class methods.)
*
* EVERY derived AR class must override this method as follows,
* <pre>
* public static function model($className=__CLASS__)
* {
* return parent::model($className);
* }
* </pre>
*
* @param string $className active record class name.
* @return CActiveRecord active record model instance.
*/
public static function model($className=__CLASS__)
{
if(isset(self::$_models[$className]))
return self::$_models[$className];
else
{
$model=self::$_models[$className]=new $className(null);
$model->_md=new CActiveRecordMetaData($model);
$model->attachBehaviors($model->behaviors());
return $model;
}
}


I could extend CModel, add the method, and then base all of my other classes off of this instead of CModel, in order to include the functionality of calling the static class. But I am wondering if this is an appropriate approach or if this is already implemented and I am just not aware of it?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users