This method will also set the component to a property.
For example:
$this->loadComponent('Acl.Acl');
Will result in a Toolbar property being set.
public loadComponent ( string $name, array $config = [] ) : |
||
$name | string | The name of the component to load. |
$config | array | The config for the component. |
return |
/** * 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']]]); } } }
/** * Convenience method for testing: Initializes the controller and the Ratings component * * @param array $params Controller params * @return void */ protected function _initControllerAndRatings($params = []) { $_default = ['?' => [], 'pass' => []]; $this->Controller->request->params = array_merge($_default, $params); if (!empty($this->Controller->request->params['?'])) { $this->Controller->request->query = $this->Controller->request->params['?']; } $this->Controller->components()->unload('Ratings'); $options = isset($this->Controller->components['Ratings.Ratings']) ? $this->Controller->components['Ratings.Ratings'] : []; $this->Controller->loadComponent('Ratings.Ratings', $options); $event = new Event('beforeFilter', $this->Controller); $this->Controller->Ratings->beforeFilter($event); //$this->Controller->Components->trigger('initialize', array(&$this->Controller)); //$this->Controller->Auth = $this->AuthComponent; //$this->Controller->Ratings->beforeFilter($this->Controller); }
/** * Creates instance of the Crud Component if it doesn't exist yet. * * @return void */ protected function _createCrudComponentInstance() { if (!$this->_registry->has('Crud.Crud')) { $this->_controller->loadComponent('Crud.Crud', $this->config()); } }
/** * Setup Auth component settings */ protected function _setupAuthComponent() { $this->controller->loadComponent('Auth', Configure::read('Auth')); }
/** * Load controller component by configure. * * @param Controller $controller * @return void */ protected static function _loadComponent(Controller $controller) { $hooks = self::_getConfigData(Hook::HOOK_CONFIG_COMPONENT_KEY); foreach ($hooks as $name => $params) { list($controllers, $config) = self::_createParams($params); if (self::_inController($controllers, $controller->name)) { $controller->loadComponent($name, $config); } } }
/** * Construct method. * * @param \Cake\Controller\Controller $controller The controller instance where the Event is dispatched. * * @return void */ public function __construct($controller) { $this->Flash = $controller->loadComponent('Flash'); }