tags:

views:

43

answers:

3

Hi all,

I am leaning cakePHP.
I noticed that a variable $name is declared in each Controller.
What is its purpose?
Is it referring to the name of table Sites?

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

If yes, Can users refer to more than one table like this?
var $name = 'Sites', 'Sites2', 'Sites3';

+2  A: 

No. $name is for PHP4 compatibility. PHP4 didn't have complete object orientated features, so it was sometimes unable to derive the name of a model from the controller class. Setting $name just made sure that wouldn't happen -- that the name of the model was explicit, so this problem wouldn't happen.

AFAIK it's totally unnecessary if you're using PHP5 and never intend to use PHP4 with your app.

Travis Leleu
+1  A: 

As far as I understand this is a legacy convention of CakePHP, mostly it works without it. Cake used this property to get Controller names right. Not that a big deal, just go with it.

sibidiba
+4  A: 

It's used for compatibility with PHP4. You can safely ignore it.

No, it;s not referring to the name of the table... It sometimes imply that controller named FooController will use model named Foo, but it's not always true.

And no, you can't specify model names like that. Models to be loaded are listed in $uses property:

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