Called after the controller action is run, but before the view is rendered. You can use this method
to perform logic or set view variables that are required on every request.
public beforeRender ( Cake\Event\Event $event ) : |
||
$event | Cake\Event\Event | An Event instance |
리턴 |
public function beforeRender(Event $event) { parent::beforeRender($event); // if (!empty($this->request->params['prefix']) && $this->request->params['prefix'] === 'admin') { // $this->layout = 'dashboard'; // } }
public function beforeRender(Event $event) { parent::beforeRender($event); if ($this->request->is('ajax')) { $this->layout = 'ajax'; } }
public function beforeRender(Event $event) { parent::beforeRender($event); $this->set('user', !is_null($this->Auth->user('id')) ? $this->Auth->user() : false); if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml'])) { $this->set('_serialize', true); } }
/** * * @param Event $event */ public function beforeRender(Event $event) { parent::beforeRender($event); $this->Cookie->config(['expires' => '+10 days', 'path' => '/']); $this->current_lang = 'en_US'; if (in_array($this->Cookie->read('lang'), array_keys(Configure::read('supported_lang')))) { I18n::locale($this->Cookie->read('lang')); $this->current_lang = $this->Cookie->read('lang'); } $this->set('current_lang', $this->current_lang); /** * * initialize the Google Client to verify the google Incomeing Stream */ $client = new \Google_Client(); $client->setClientId(Configure::read('GPLUS.client_id')); $client->setClientSecret(Configure::read('gplus.secret')); $client->setRedirectUri(Router::url(['controller' => 'users', 'action' => 'gpluslogin', '_full' => true])); $client->setScopes('email'); $this->set('isFrontPage', $this->isFrontPage); $this->set('current_user', $this->current_user); $this->set('isUserLoggedIn', $this->isUserLoggedIn); }
/** * Configure the Helper and do automatic render setup if needed * * @param Event $event */ public function beforeRender(Event $event) { parent::beforeRender($event); $this->helpers['CrudViews.Crud'] = ['_CrudData' => $this->_CrudData, 'actions' => ['_ModelActions' => $this->_ModelActions, '_AssociationActions' => $this->_AssociationActions, '_RecordActions' => $this->_RecordActions]]; }
public function beforeRender(Event $event) { parent::beforeRender($event); $this->set('breadcrumbs', $this->breadcrumbs); $this->set('showBreadcrumb', $this->showBreadcrumb); }
public function beforeRender(Event $event) { parent::beforeRender($event); if ($this->Auth->user()) { $this->loadModel('Users'); $user = $this->Users->get($this->Auth->user()['id']); $user->last_access = Time::now(); $this->Users->save($user); /* $limitOnline = new Time('10 minutes ago'); $onlineUsers = $this->Users->find()->where(['last_access >=' => $limitOnline, 'id <> '=>$this->Auth->user()['id']]); $nonOnlineUsers = $this->Users->find()->where(['last_access <' => $limitOnline, 'id <> '=>$this->Auth->user()['id']]); $newMessagesUsers = $this->Users->find()->select([ 'Users.id','Users.login', ])->join([ 'Chat' => [ 'table' => 'chat', 'type' => 'INNER', 'conditions' => 'Chat.to_user_id = Users.id ', ] ])->where([ 'Chat.created > Users.last_access', 'Users.id' => $this->Auth->user()['id'] ]); */ } /* $this->set('onlineUsers', $onlineUsers); $this->set('nonOnlineUsers', $nonOnlineUsers); $this->set('newMessagesUsers', $newMessagesUsers); */ }
/** * @param \Cake\Event\Event $event * @return \Cake\Network\Response|null|void */ public function beforeRender(Event $event) { parent::beforeRender($event); // Automatically shim $this->request->data = $this->Model->find() etc which used to be of type array if (!empty($this->request->data) && $this->request->data instanceof Entity) { $this->request->data = $this->request->data->toArray(); } }
public function beforeRender(Event $event) { parent::beforeRender($event); //ALLOW CONTROLLER ACTIONS $this->Auth->allow('load_pages', 'home', 'article_view', 'rss', 'categories', 'contact', 'captcha_image'); $this->loadModel('Navigation'); $this->set('main_navigation', $main_navigation = $this->Navigation->find('all', array('order' => 'position ASC'))); $this->loadModel('Sidebar'); $this->set('main_sidebar', $main_sidebar = $this->Sidebar->find('all', array('order' => 'position ASC'))); $this->loadModel('Categories'); $this->set('sidebar_categories', $sidebar_categories = $this->Categories->find('all', array('order' => 'title ASC'))); }
public function beforeRender(Event $event) { parent::beforeRender($event); // Handling the breadcrumb $this->set('breadcrumb', $this->breadcrumb); $this->getView()->theme = 'AppUi'; }
public function beforeRender(Event $event) { parent::beforeRender($event); if ($this->request->query('is_dialog')) { //TODO: convert popup dialog to a plugin $this->viewBuilder()->layout('admin_popup'); } }
public function beforeRender(Event $event) { parent::beforeRender($event); $this->layout = 'admin'; }
public function beforeRender(Event $event) { parent::beforeRender($event); $this->set('imageFields', $this->imageFields); $this->handleAjaxFormRequest(); $this->set('titleLayout', $this->titleLayout); }
/** * beforeRender hook method. * * @param Event $event The beforeRender event that was fired. * * @return void */ public function beforeRender(Event $event) { parent::beforeRender($event); if ($this->components()->has('Auth')) { $builder = $this->viewBuilder(); $builder->helpers(['Acl' => $this->Auth->config('authorize')['Acl.Actions']]); } }
/** * Before render callback. * * @param \Cake\Event\Event $event The beforeRender event. * @return void */ public function beforeRender(Event $event) { parent::beforeRender($event); $isRest = in_array($this->response->type(), ['application/json', 'application/xml']); if (!array_key_exists('_serialize', $this->viewVars) && $isRest) { $this->set('_serialize', true); } }