2012-04-17 48 views
5

我試圖從本地移到我的代碼服務器 當我嘗試登錄到應用授權適配器沒有在CakePHP

enter image description here

Here is my AppController 
class AppController extends Controller{ 
    /* Determines what logged-in users access to */ 
    var $components = array('Auth','Session'); 

    public function isAuthorized($user){ 
     return true; 
    } 

    public function beforeFilter(){ 
     $userdetails = array(); 
     $this->Auth->autoRedirect = false; 
     $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); 
     $this->Auth->loginRedirect = array('controller' => 'matches', 'action' => 'index'); 
     $this->Auth->authorize = 'controller'; 
     $this->Auth->authError= 'You need permissions to access this page'; 
     $this->Auth->allow('users'); 
     $this->set('Auth',$this->Auth); 
     $userdetails = $this->Auth->user(); 
     $this->set('myUser', $userdetails['username']); 
     $this->set('myRole', $userdetails['user_role_id']); 
     $this->set('pStatus', $userdetails['password_status']); 
    } 
} 


Here is my Login Action in UsersController 
public function login(){ 
     $this->Auth->autoRedirect = false; 
     $id = $this->Auth->user('id'); 
     if(empty($id)){ 
      if($this->request->is('post')){ 
       if($this->Auth->login()){ 
        $this->redirect($this->Auth->redirect()); 
       }else{ 
        $this->Session->setFlash('Invalid Username or password'); 
       } 
      } 
     }else{ 
      $this->redirect(array('action'=>'index')); 
     } 
    } 

感謝您的幫助

回答

12
發現

您在beforeFilter中授權控制器的部分應正確大寫:

因此:

$this->Auth->authorize = 'Controller';

相反的:

$this->Auth->authorize = 'controller';

這個特定的語句試圖找到controllerAuthorize.php和應該尋找ControllerAuthorize.php。這不會在Windows上造成問題,但它在Unix系統上會有問題。

+0

我怎麼能錯過這些小問題。你讓我的一天男人 – 2012-04-17 10:50:15

+1

看來,老話說「魔鬼在細節中」依然如此。不客氣。 ;) – mensch 2012-04-17 11:02:03

+2

它也沒有通知在Mac OS X.只是說'... ^^ – 2012-07-12 14:29:18