Created
November 6, 2015 09:44
-
-
Save anhtuank7c/a943d159841d9535cef5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
use App\Event\CheckProfileListener; | |
use Cake\Event\Event; | |
/** | |
* CheckProfile trait | |
*/ | |
trait CheckProfile { | |
public function beforeFilter(Event $event) { | |
parent::beforeFilter($event); | |
$this->eventManager()->on(new CheckProfileListener($this->Auth)); | |
} | |
} |
<?php
namespace App\Controller;
/**
* CheckProfile trait
*/
trait CheckProfileTrait {
public function implementedEvents() {
return ['Controller.beforeFilter' => 'myBeforeFilter'];
}
public function myBeforeFilter() {
throw new \Cake\Network\Exception\NotFoundException('hahaha');
}
}
And
<?php
namespace App\Controller\Admin;
use App\Controller\AppController;
use App\Controller\CheckProfileTrait;
use Cake\Event\EventListenerInterface;
/**
* Dashboard Controller
*
* @property \App\Model\Table\DashboardTable $Dashboard
*/
class DashboardController extends AppController implements EventListenerInterface {
use CheckProfileTrait;
/**
* Index method
*
* @return void
*/
public function index() {
}
}
But cannot throw Exception
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CheckProfileTrait.php:
'myBeforeFilter']; } ``` public function myBeforeFilter() { throw new \Cake\Network\Exception\NotFoundException('hahaha'); } ``` } DashboardController.php: