Php 未授权错误。。。cakefolder/两次

Php 未授权错误。。。cakefolder/两次,php,oop,cakephp,cakephp-2.0,cakephp-2.3,Php,Oop,Cakephp,Cakephp 2.0,Cakephp 2.3,我遇到了一个问题,当我在我的应用程序控制器中添加'authorize'=>array('Controller'),时,每次我按edit或add或login,它都会转到以下地址: localhost/cakefolder/cakefolder 我得到了这个错误: 错误:找不到cakefolderController 但是当我从appController中删除'authorize'=>数组(“控制器”)时,一切正常 AppController.php <?php

我遇到了一个问题,当我在我的应用程序控制器中添加'authorize'=>array('Controller'),时,每次我按edit或add或login,它都会转到以下地址:

localhost/cakefolder/cakefolder

我得到了这个错误:

错误:找不到cakefolderController

但是当我从appController中删除'authorize'=>数组(“控制器”)时,一切正常

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());



}

 }
     <?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'));
}
             }
   <?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;
} 





    }  

loginDirect
logoutRedirect
设置中,尝试在
controller
中使用小写的
c
。每当通过数组构建URL时,通常在键中使用小写

其次,您的基本url设置可能存在问题。
Auth
组件正在识别您需要进行身份验证,因此它试图将您重定向到
users/index
,这也可能是
/
的默认路由器。但是,不要转到
http://localhost/cakefolder
http://localhost/cakefolder/users/index
,它将成为
http://localhost/cakefolder/cakefolder

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