Where to find those $this-> functions?

Hello,

I would like if any of you has a full list of all the function names using $this-> like all the ones we find in controllers please.

It would be easier for me to have a full list rather than trying to find them in the doc(which I do not really understand to be honest).

$this->redirect

$this->render

$this->findModel

Thank you,

Ben

Do you use any IDE? Like Netbeans or PHPStorm? If not I strongly suggest to start using one of those because it will make your coding life 1000000% easier and you will not have problems like the one you have given.

Hi Bizley,

I see what you mean now, in Netbeans I types $this-> and all the functions started to show, yes for sure it makes it a bit easier :-))))

Thanks!

Ben

you should take a look to the Yii2 API documentation as it describes all methods (the '$this-> functions) and members (the $this-> variables) for all classes of yii2.

For example check out the Public Method section of Controller Doc …

ciao

Thanks Raoul,

My problem is that I do find the Yii2 doc very complicated(for a beginner level).

Ben

Controller docs

every item you see on that page in blue can be used with $this->…

also, they type refers to what the value after the attribute has to be.

i.e.

in the controller docs Under Public Properties

there is a property called layout. The type says strin|boolean so that means it can only be a string or boolean


$this->layout='someSting';

$this->layout=FALSE;//true would also be valid

are the only two valid types for layout. Same logic goes for all documentation.

Also, if you are in any of the subclasses listed on that page then $this->… for controller would still be accessible because it would be inherited. However, in each of the subclasses there will be more options that would now be accessible with $this->…

furthermore, $this just refers to the current class your in.

so if you were in a view $this->… would now refer to yii\base\View

I’d spend some time learning how to read docs. The yii2 docs are just like any other docs and will make your life a lot easier in the long run when using plugins, extension and just coding with yii2.

Thank you so much for taking the time to explain everything in detail, this is great!

One thing I have noticed in the views is sometime you have lines of code commented out like this one for example:

/* @var $this yii\web\View */

Why that please?

Does this means that all the variables from the classes are being pulled from the base class?

Thank you,

Ben

These comments are there to inform you (or any other one who looks at the code) what the variables in this files are "holding" / instance of.

Basically it only means:

variable $this is a instance from yii\web\View

(app/vendor/yiisoft/yii2/web/View.php)

Or for example:

/* @var $model app\models\Comment */

Means:

In the file you are currently looking at the variable $model is a instance of app/models/Comment.php

Regards

just what meta said and really goes back to your first question

$this = class yii/web/view

Thank you so much! Go it:-))

Ben