Custom model properties

I’m trying to get my head ahead models in 2.0 and getting stuck with something really basic! I have some functions on a model, some static some not, but if i try and access them i just get this error

Call to undefined method Yii::app()

I’m trying to access them either like this

$value=MyModel::myStaticFunction();

(in 1.x I would have something like MyModel::model()->myFunction();

or

$model= new MyModel();

$value=model->myOtherFunction();

Can’t seem to get either to work at all but must be doing something silly…?

you should read the docs for yii2


Yii::app()

// use this instead

Yii::$app




MyModel::model()

// has been renamed to 

MyModel::find()


// however this should work fine

$model= new MyModel();

$value=model->myOtherFunction();



Thanks, just so I can read up where is the first point you mention in the docs? I looked at the model section of the guide to 2.0 but didn’t spot that point.

hey oaks I dont think the first one is under models but you will find many cases where it has been used and talked about throughout

for instance in create action its being used to get data from request component

http://www.yiiframework.com/doc-2.0/guide-structure-controllers.html#actions