Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp: Load components in components

Tags:

cakephp

in app_controller.php load Session, Auth components.

And in posts_controller.php, i use CustomComponent with $components = array('Session','Auth');

Then do CustomComponent must reload Session, Auth components?

if i use and create much components and that components use other components .It will make app is very slow?


I asked in cakephp IRC, A person answer is not:

[11:05] it will not be slow, I believe it passes those around via reference

[11:05] so you have nothing to worry about

like image 543
meotimdihia Avatar asked May 24 '26 12:05

meotimdihia


2 Answers

Lets say you want to import BComponent into AComponent.

AComponent

class AComponent extends Component {
     public $components = array('BComponent');

     public function xyz(){
           $test = $this->BComponent->abc($name);
           echo $test;
     }
}

BComponent

class BComponent extends Component {

     public function abc($name){
           return "My name is: ". $name;
     }
}
like image 152
Fury Avatar answered May 27 '26 03:05

Fury


yes, it would need to be $components = array('Session','Auth','Custom'); Or you can use: App::import('Component', 'Custom');$Custom = new CustomComponent();

Then do CustomComponent must reload Session, Auth components? If you don't use Session or Auth inside your CustomComponent class, then no.

It will make app is very slow? No, unless you use a lot of components.

like image 28
Anh Pham Avatar answered May 27 '26 03:05

Anh Pham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!