Correct using component in another components

Hi. I need to call component in another component. In official documentation CakePHP they recommend add component to variable $components. But I need call component in different functions and send different params. How can I call component?

In controller I use loadComponent and put params to component initialize method (constructor)


Please share more details about your scenario. “call component in different function and send different params” is extremely generic, so we can’t really give a meaningful reply.

Okay. I have component witch create socket connection via proxy and I have another component with functions which connect to different endpoints. I need load component in every function with different params.

Sounds like those parameters should be included in whatever call you’re making to the component in “every function”, rather than included in the configuration when you add the component.

Yes, but this parameters must be passed to the component constructor. When I add component via $components variable I can put my custom parameters, but how can I call component with different parameters in another place in my component?

Why must they be passed in the constructor? Maybe share some code to demonstrate your problem.

I have resolve my problem.

Component A:

class A extends Component 
    public function initialize(array $config)
        //logic for handling params from $config
    //another methods

Component B:

class B extends Component 
    $components = ['A'];

    public function funcB()
            'param' => value
        //call another method of A component