What is the purpose of declaring $ name in each controller

I am leaning towards cakePHP.
I noticed that the $ name variable is declared in every controller.
What is its purpose?
Does this refer to the title of tabular sites?

<?php
class SitesController extends AppController { 
var $name = 'Sites';
...
}
?>

      

If yes, can users refer to more than one table as follows?
var $ name = 'Sites', 'Sites2', 'Sites3';

+2


a source to share


3 answers


It is used for PHP4 compatibility. You can safely ignore it.

No, this does not apply to the table name ... Sometimes it is assumed that a controller named FooController will use a model named Foo, but this is not always true.



And no, you cannot specify model names like that. Loadable models are listed in the property $uses

:

public $uses = array ('Sites', 'Sites2', 'Sites3');

      

+6


a source


No. $ name for PHP4 compatibility. PHP4 didn’t have complete object oriented functionality, so it sometimes failed to get the model name from the controller class. Setting $ name just made sure it didn't - that the name of the model was explicit, so there wouldn't be this problem.



AFAIK absolutely unnecessary if you are using PHP5 and never intend to use PHP4 with your application.

+2


a source


As far as I understand, this is CakePHP's conditional convention, it mostly works without it. Cake used this property to get the controller names correctly. Not that important, just go with it.

+1


a source







All Articles