If you are inside UsersController, what purpose does the $this->User part of the statement "$this->User->find('all');" serve?
What is the $this referencing? Is it an instance of something? What is the current object in this case?
If you are inside UsersController, what purpose does the $this->User part of the statement "$this->User->find('all');" serve?
What is the $this referencing? Is it an instance of something? What is the current object in this case?
From the CakePHP Manual - Beginning with Cake
This manual assumes that you have a general understanding of PHP and a basic understanding of object-oriented programming (OOP).
There are thousands of sites on the web that will explain OOP and PHP to you. Here are two random ones.
Objected Oriented Programming and Object Oriented Programming with PHP
$this // is the current class
$this->User // is the calling the Model User
The default behavior in Cake is to automatically associate a model with each controller. The convention is that the associated model will be the singular of the controller name so UsersController will automatically load the model named User, PeopleController will automatically load the model named Person. The models that are autoloaded like this then become available as attributes of your controller object.
You can choose which models are auto loaded for a controller by setting the $uses attribute of the controller object to an array containing the names of the models you want loaded although this is generally considered bad practice due to performance issues.
You can also set the $uses attribute to false if you do not wish to associate any model with your controller.
To load model instances at a later stage in your controller you can call $this->loadModel('Cow') and $this->Cow will now contain a reference to your Cow model.