CakephpのAuthComponentに認証なしのAction追加
Mar 3, 2011AD:
		
		
	
	Cakephpで構築したサイトにAuthComponentを使用して、ユーザ機能を実装していた際に、
微妙に悩んだのが、UsersControllerの中で、addのアクションだけ、認証の必要なしにアクセスするの方法です。
答えは、beforeFilterに、$this->Auth->allow(‘add’);を入れれば解決でした。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | class r extends AppController {   var $name = 'Users';   var $components = array('Auth');   var $helpers = array('image','Html','Ajax','Javascript','Form');   //初期値の読み込み   function beforeFilter(){     $this->Auth->fields = array(      'username' => 'email',      'password' => 'password'      );     $this->Auth->loginError = "パスワードもしくはログインIDをご確認下さい。";     $this->Auth->authError = "ご利用されるにはログインが必要です。";     $this->Auth->allow('add');   }   function login() {     if ($this->Auth->user()) {         $this->redirect('/');     }   }   function logout() {   $this->Auth->logout();   $this->redirect('/');   }   function add() {     if (!empty($this->data)) {       if($this->User->save($this->data)) {         $this->User->create();         $this->Session->setFlash("当労苦しました。");         $this->redirect('/');       }     }   } | 
		AD:
			
			
		
		
	

 Ayumi Mizoshiri
Ayumi Mizoshiri







No Comments, Comment or Ping
Reply to “CakephpのAuthComponentに認証なしのAction追加”
Warning: Undefined variable $user_ID in /home/sazaeau/mizoshiri.com/public_html/blog.mizoshiri.com/wp-content/themes/grid_focus_public_mizo/comments.php on line 66
You must be logged in to post a comment.