isAuthorized错误. .Cakefolder /两次


isAuthorized Error... cakefolder/ two times

我有一个问题,当我添加'授权' =>数组('控制器'),在我的应用程序控制器每次我按编辑或添加或登录它会到以下地址:

localhost/cakefolder cakefolder

,我得到这个错误:

错误:cakefolderController could not found.

但是当我从appController中删除'authorize' => array('Controller'),一切都恢复正常

.

AppController.php

         <?php
      class AppController extends Controller {

public $helpers = array('Html', 'Session', 'Form' );
public $components = array(
'DebugKit.Toolbar',
'Session', 
'Auth' => array(
'authorize' => array('Controller'),
'authenticate' => array(
'Form' => array(
'passwordHasher' => 'Blowfish',
'loginRedirect'=>array('Controller'=>'user', 'action'=>'index'),
'logoutRedirect'=>array('Controller'=>'user', 'action'=>'index'),
'authError'=>"you are not allowed to access that page",
    )
)
)
); 

public function beforeFilter() {
    $this->Auth->allow('index', 'add');
    $this->set('logged_in', $this->Auth->loggedIn());
    $this->set('current_user', $this->Auth->user());

}
 }

UserController.php

     <?php
       App::uses('AppController', 'Controller');

     class UsersController extends AppController {

public function beforeFilter() {
    parent::beforeFilter();
    $this->Auth->allow('add');
}

// This is to let user edit and delete only their own information
  public function isAuthorized($user) {
if (in_array($this->action, array('edit','delete'))) {
    if ($user['id'] != $this->request->params['pass'][0]) {
        return false;
    }   
    return true;
}
       }   

    public function login() {
if ($this->request->is('post')) {
    if ($this->Auth->login()) {
        return $this->redirect($this->Auth->redirect());
    }
    $this->Session->setFlash(__('Invalid username or password, try again'));
  }
  }

public function logout() {
    $this->Auth->logout();
    $this->redirect('index');
}

public $components = array('Paginator', 'Session');

public function index() {
    $this->User->recursive = 0;
    $this->set('users', $this->Paginator->paginate());
}

public function view($id = null) {
    if (!$this->User->exists($id)) {
        throw new NotFoundException(__('Invalid user'));
    }
    $options = array('conditions' => array('User.' . $this->User->primaryKey =>    $id));
    $this->set('user', $this->User->find('first', $options));
}

public function add() {
    if ($this->request->is('post')) {
    //  $this->User->create();
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
        }
    }
}

public function edit($id = null) {
    if (!$this->User->exists($id)) {
        throw new NotFoundException(__('Invalid user'));
    }
    if ($this->request->is(array('post', 'put'))) {
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
        }
    } else {
        $options = array('conditions' => array('User.' . $this->User->primaryKey => $id));
        $this->request->data = $this->User->find('first', $options);
    }
}

public function delete($id = null) {
    $this->User->id = $id;
    if (!$this->User->exists()) {
        throw new NotFoundException(__('Invalid user'));
    }
    $this->request->allowMethod('post', 'delete');
    if ($this->User->delete()) {
        $this->Session->setFlash(__('The user has been deleted.'));
    } else {
        $this->Session->setFlash(__('The user could not be deleted. Please, try again.'));
    }
    return $this->redirect(array('action' => 'index'));
}

public function full_index() {
    $this->User->recursive = 0;
    $this->set('users', $this->Paginator->paginate());
}


public function full_view($id = null) {
    if (!$this->User->exists($id)) {
        throw new NotFoundException(__('Invalid user'));
    }
    $options = array('conditions' => array('User.' . $this->User->primaryKey =>   $id));
    $this->set('user', $this->User->find('first', $options));


}

public function full_add() {
    if ($this->request->is('post')) {
        $this->User->create();
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
        }
    }
}

public function full_edit($id = null) {
    if (!$this->User->exists($id)) {
        throw new NotFoundException(__('Invalid user'));
    }
    if ($this->request->is(array('post', 'put'))) {
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved.     Please, try again.'));
        }
    } else {
        $options = array('conditions' => array('User.' . $this->User- >primaryKey => $id));
        $this->request->data = $this->User->find('first', $options);
    }
}

public function full_delete($id = null) {
    $this->User->id = $id;
    if (!$this->User->exists()) {
        throw new NotFoundException(__('Invalid user'));
    }
    $this->request->allowMethod('post', 'delete');
    if ($this->User->delete()) {
        $this->Session->setFlash(__('The user has been deleted.'));
    } else {
        $this->Session->setFlash(__('The user could not be deleted. Please,      try again.'));
    }
    return $this->redirect(array('action' => 'index'));
}
             }

User.php

   <?php
     App::uses('AppModel', 'Model', 'Security', 'Utility');
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');

    class User extends AppModel {


            // hash password before saving It  

       public function beforeSave($options = array()) {
    // if ID is not set, we're inserting a new user as opposed to updating
    if (!$this->id) {
        $passwordHasher = new BlowfishPasswordHasher();
      $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this- >alias]['password']);
    }
       return true;
  }



public $primaryKey = 'user_id';
public $displayField = 'username';

public $validate = array(


//USERNAME VALIDATION
'username' => array(
        'required' => array(
            'rule' => array('minLength', 1),
            'allowEmpty' => false,
            'message' => 'Please enter a title.'
        )          
   ),
    'username' => array(
        'required' => array(
            'rule' => array( 'isUnique' ),
            'message' => 'Username already exist. Please try again',
            //'allowEmpty' => false,
            //'required' => TRUE,
            //'last' => TRUE, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
        ),


        //EMAIL ADDRESS VALIDATION
'email_address' => array(
        'required' => array(
            'rule' => array('minLength', 1),
            'allowEmpty' => false,
            'message' => 'Please add an email'
        )          
   ),
    'email_address' => array(
        'required' => array(
            'rule' => array( 'isUnique' ),
            'message' => 'Email already exist in our database. Please try again',
            //'allowEmpty' => false,
            //'required' => TRUE,
            //'last' => TRUE, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or    'update' operations
        ),
        ),
/*'email_address' => array(
        'required' => array(
            'rule' => array( 'email' ),
            'message' => 'Please add a correct email',
            //'allowEmpty' => false,
            //'required' => TRUE,
            //'last' => TRUE, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
        ),  */

        //PASSWORD VALIDATION
/*  'password' => array(            
    'minLength' => array(
        'rule' => array('minLength', 6),
        'message' => 'Your password must be at least 6 characters long.'
    ),
    'notempty' => array(
        'rule' => 'notEmpty',
        'message' => 'Please fill in the required field.'
    )
),
'password_confirmation' => array(
    'identical' => array(
        'rule' => array('matchPasswords'),
        'message' => 'Password confirmation does not match password.'
    ), */

 'password'=>array(
 'not empty' => array(
 'rule'=>'notEmpty',
 'Message'=>'Password is empty'
 ),
 'Match Passwords'=> array(
  'rule'=>'matchPasswords',
  'message'=>'Password do not match'
 )
 ),            
  'password_confirmation'=>array(
   'not empty' => array(
 'rule'=>'notEmpty',
 'Message'=>'verify password'
 )
  )


/*  'user_id' => array(
        'alphaNumeric' => array(
            'rule' => array('alphaNumeric'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ), */

    );

// PASSWORD CONFIRMATION VALIDATION FUNCTION 
 public function matchPasswords($data){
    if ($data['password'] == $this->data['User']['password_confirmation']) {
        return True;
    }
    $this->invalidate('password_confirmation', 'Your password do not match');
    return FALSE;
} 


    }  

尝试在loginRedirectlogoutRedirect设置中使用controller中的小写c。当URL通过数组构建时,按惯例在键中使用小写。

其次,您的基本url设置可能有问题。Auth组件认识到您需要进行身份验证,因此它试图将您重定向到users/index,这也可能恰好是/的默认路由器。然而,它不是去http://localhost/cakefolderhttp://localhost/cakefolder/users/index,而是去http://localhost/cakefolder/cakefolder

能否确认文档根目录的URL ?并检查baseUrl的值设置