Cake\Controller\Component::initialize PHP Method

initialize() public method

Implement this method to avoid having to overwrite the constructor and call parent.
public initialize ( array $config ) : void
$config array The configuration settings provided to this component.
return void
    public function initialize(array $config)
    {
    }

Usage Example

Example #1
1
 /**
  * initialize
  *
  * @param array $config Config.
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->setController($this->_registry->getController());
     // adding request handler
     $this->Controller->loadComponent('RequestHandler');
     // accepts json
     $this->Controller->RequestHandler->renderAs($this->Controller, 'json');
     // set the default modelName
     if (is_null($this->config('modelName'))) {
         $this->config('modelName', $this->Controller->name);
     }
     if (Configure::read('Api.JWT')) {
         if ($this->Controller->Auth) {
             $this->Controller->Auth->config('authenticate', ['ADmad/JwtAuth.Jwt' => ['parameter' => '_token', 'userModel' => 'Users.Users', 'scope' => ['Users.active' => 1], 'fields' => ['id' => 'id']]]);
         }
     }
 }
All Usage Examples Of Cake\Controller\Component::initialize