◆バージョン:2.4.6
◆Controller: UsersとPosts
以下のように「Users」コントローラに$componentsを書き、ログインをしなくても「add」アクションを実行できるよう設定しています。
Users(こちらは正常に機能しています)↓
public $components = array('Auth'=>array('loginRedirect'=>array('controller' => 'users' , 'action' => 'index'))); public function beforeFilter(){ $this->Auth->allow('add'); }
上記と同じように「Posts」コントローラでも$componentsを宣言し、ログインをしなくても実行されるアクションを作成したいのですが以下のように書くとエラーが発生してしまいます。
Posts(エラーとなる)↓
public $components = array('Auth'); public function beforeFilter(){ $this->Auth->allow('index'); }
エラー↓
Error: Cannot redeclare PostsController::$components
__public $components = array('Auth');__を2回書いていることが原因でしょうか?
再宣言はできないというエラーが出ているように思えるのですが・・。
一度宣言した$componentsを他のControllerでも使用したい場合はどのようにすればいいでしょうか?
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー