Answer the question
In order to leave comments, you need to log in
How to deal with the current model from the base model in Yii?
Hey!
There is a Basic, model with all sorts of typical actions. I figured out static methods, for example, to get all published records, I do this:
class ActiveRecord extends CActiveRecoed{
...
static function getAll(){
$criteria = new CDbCriteria();
$criteria->condition = 'EXIST = ' .STATUS_PUBLIC;
$model = self::model(get_called_class())->findAll($criteria);
return $model;
}
public function published(){
$criteria = new CDbCriteria();
$criteria->condition = 'EXIST = '.STATUS_PUBLIC;
$model = $this::model(get_called_class())->findAll($criteria);
return $model;
}
Answer the question
In order to leave comments, you need to log in
Instead of this:
Use the same method as in the first case
Here, most likely, there is a misunderstanding of how inheritance works in php in particular and OOP in this language in general. I advise you to read the book by Matt Zandstra "PHP. Objects, Patterns and Programming Techniques"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question