E
E
EVOSandru62015-05-03 04:54:41
Yii
EVOSandru6, 2015-05-03 04:54:41

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;
    }

But with a public method that does the same thing - a problem,
public function published(){
        $criteria = new CDbCriteria();
        $criteria->condition = 'EXIST = '.STATUS_PUBLIC;
        $model = $this::model(get_called_class())->findAll($criteria);
        return $model;
    }

how to write it correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Makarov, 2015-05-03
@vollossy

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 question

Ask a Question

731 491 924 answers to any question