When I click on a link of my site it gives an exception of Undefined property: ErrorController::$Authentication
This is the code of beforeRender:
public function beforeRender(\Cake\Event\EventInterface $event)
{
parent::beforeRender($event);
$result = $this->Authentication->getResult();
// If the user is logged in send them away.
$this->loadModel('Controllers');
$this->loadModel('GridOperations');
$controller = $this->Controllers->find('all')->where(['name' => $this->request->getParam('controller')])->first();
if($result->isValid() && !empty($controller)) {
$user = $this->Authentication->getIdentity();
$gridOperationsAdd = $this->GridOperations->find('all')->where(['profile_id'=>$user->profile_id, 'controller_id'=>$controller->id, 'sort_order' => 0])->first();
$gridOperations = $this->GridOperations->find('all')->where(['profile_id'=>$user->profile_id, 'controller_id'=>$controller->id, 'sort_order >' => 0])->order(['sort_order' => 'ASC']);
$countAdd = $this->GridOperations->find('all')->where(['profile_id'=>$user->profile_id, 'controller_id'=>$controller->id, 'sort_order' => 0])->count();
$countOperations = $this->GridOperations->find('all')->count();
$this->set('countAdd', $countAdd);
$this->set('countOperations', $countOperations);
$this->set(compact('gridOperationsAdd', 'gridOperations'));
}
}
How can I solve this problem?