初心者なのですが、CakePHP2.5.2から3.6.7への移行を行っています。
以下の流れとなってしまい、④ではA200ControllerのbeforeFilter()が呼び出されると思っていましたが
A100ControllerのbeforeFilter()が呼び出されています。
解決方法を教えてください。
実際(CakePHP3.6.7)の流れ
①ブラウザからのリクエストhttp://localhost/A100&id=0001
②共通のコントローラのinitialize()が呼び出される
cakePHP
1class AppController extends Controller { 2 public $components = array('App'); 3 4 public function beforeFilter() { 5 /* 共通処理 */ 6 } 7 public function initialize() 8 { 9 parent::initialize(); 10 $this->loadComponent('RequestHandler', [ 11 'enableBeforeRedirect' => false, 12 ]); 13 $this->loadComponent('Flash'); 14 $this->loadComponent('Security'); 15 $this->Session = $this->request->session(); 16 } 17}
③共通のコンポーネントのinitialize()が呼び出される
ここでredirect('http://localhost/A200')を呼び出しています。
cakePHP
1class AppComponent extends Component { 2 public function initialize(array $config) { 3 $controller = $this->_registry->getController(); 4 $this->Session = $this->request->session(); 5 6 if ( /* 判定処理 */ ) { 7 /* このタイミングではここを通過します */ 8 /* $checkPageは'A200' */ 9 /* リクエストをセッションに格納 */ 10 return $controller->redirect($controller->baseUrl. $checkPage); 11 } 12 13 $this->redirectToken($controller); /* 独自処理 */ 14 } 15}
④A100ControllerのbeforeFilter()が呼び出される
cakePHP
1class A100Controller extends ContactController { 2 public function beforeFilter() { 3 parent::beforeFilter(); 4 /* 独自処理 */ 5 } 6 public function index() { 7 /* 独自処理 */ 8 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/30 01:20