0
votes

I was reading the following paragraph at https://book.cakephp.org/1.2/en/The-Manual/Developing-with-CakePHP/Controllers.html#the-app-controller:

"While normal object-oriented inheritance rules apply, CakePHP also does a bit of extra work when it comes to special controller attributes, like the list of components or helpers used by a controller. In these cases, AppController value arrays are merged with child controller class arrays."

In my AppController class I have this:

var $components = array(
    'Security',
    'Pdf'
);

In another controller that extends AppController, I have this:

var $components = array(
    'Paypal'
);

Since the theory says this:

"AppController value arrays are merged with child controller class arrays"

Does it mean that in my controller that extends AppController, merging components would be in this case the equivalent of having the following available?:

var $components = array(
    'Security',
    'Pdf',
    'Paypal'
);

Thank you.

2
Whatever we store in the $components variable initialized in the AppController class, what we are basically saying is: "Load this component and make it available in all of the sub-CakePHP classes whose parent is the AppController class." - Jaime Montoya
FYI, var has not been used by any competent developer since PHP5.0 was released (around 2005th). - tereško
@tereško Thank you for your note about using "var" and I guess that may have been an indirect way to call me an incompetent developer. Whether you use "var" or not will depend on the version of PHP that you are using. As you may have noticed, the version of CakePHP that I am citing in the references is CakePHP 1.2. Not surprising if the PHP version for this implementation was old as well. - Jaime Montoya
@tereško From the official documentation at php.net/manual/en/language.oop5.visibility.php: "Note: The PHP 4 method of declaring a variable with the var keyword is still supported for compatibility reasons (as a synonym for the public keyword). In PHP 5 before 5.1.3, its usage would generate an E_STRICT warning." - Jaime Montoya
I hope you are getting really well paid for working on an ancient project. - tereško

2 Answers

1
votes

You would only have the 3 components available in the class that declares using the Paypal component. Another controller which didn't declare it explicitly would only have the 2 original components on hand. This is vertical inheritance, not lateral one, if that makes any sense?

Note that you're quoting the book for a very obsolete version of cake. I understand, I'm stuck with a 1.3 dinosaur myself :-). But I've found it useful to consult the latest version of the book as well. While the details are often different, it's more fleshed out, and it tends to explain the general principles much better.

-1
votes

According to https://book.cakephp.org/1.2/en/The-Manual/Developing-with-CakePHP/Controllers.html#the-app-controller:

"CakePHP merges the following variables from the AppController to your application’s controllers: $components, $helpers and $uses."

Based on that information, after merging, what I understand is that the final result would be:

var $components = array(
    'Security',
    'Pdf',
    'Paypal'
);