Sanganabasu
Sanganabasu

Reputation: 927

CakePHP Calling Component Constructor with argument

I am using cakephp 2.1 version and created a component as GoogleApiComponent as follows.

class GoogleApiComponent extends Component {
  public $client;
  public $analytics;
  function __construct($prompt = null) {
      $this->client = new apiClient();
      $this->client->setApprovalPrompt($prompt);
      $this->analytics = new apiAnalyticsService($this->client);
  }

}

Then in AppController, I included the above component.

public $components = array('GoogleApi');

After an user logs in, I have to check some conditions in beforeFilter() method of AppController and according to that conditions I have to change the argument of GoogleAPiComponent Constructor. So How this get it done? the work is more appreciable..

Upvotes: 1

Views: 1936

Answers (1)

nanoman
nanoman

Reputation: 1069

You can pass a $settings array to your components.

See http://book.cakephp.org/2.0/en/controllers/components.html#configuring-components

Inside your component you can access the array via $this->settings

Upvotes: 1

Related Questions