lithium\action\Controller::_init PHP Method

_init() protected method

Populates the $response property with a new instance of the Response class passing it configuration, and sets some rendering options, depending on the incoming request.
protected _init ( ) : void
return void
    protected function _init()
    {
        parent::_init();
        foreach (static::_parents() as $parent) {
            $inherit = get_class_vars($parent);
            if (isset($inherit['_render'])) {
                $this->_render += $inherit['_render'];
            }
            if ($parent === __CLASS__) {
                break;
            }
        }
        $this->request = $this->request ?: $this->_config['request'];
        $this->response = $this->_instance('response', $this->_config['response']);
        if (!$this->request || $this->_render['type']) {
            return;
        }
        if ($this->_render['negotiate']) {
            $this->_render['type'] = $this->request->accepts();
            return;
        }
        $this->_render['type'] = $this->request->get('params:type') ?: 'html';
    }

Usage Example

 public function _init()
 {
     parent::_init();
     /*
     * 
     * if (!Session::read('user'))
      $this->redirect('Sessions::add');
     
     
      alliances::applyFilter('save', function($self, $params, $chain) {
     
      //Temporarily store our entity object so that we can manipulate it
      $record = $params['entity'];
     
      //If an id doesn't exist yet, then we know we're saving for the first time. If a
      //password is provided, we need to hash it
      var_dump($record->foto);
     
      //Write the modified object back to $params
      $params['entity'] = $record;
     
      //Allow the next filter to be run
      return $chain->next($self, $params, $chain);
      });
     * 
     * 
     */
 }
All Usage Examples Of lithium\action\Controller::_init