2

我知道我应该能够通过 [mydomain.com]/users/[controller] 使用用户插件,例如 mydomain.com/users/login 或 mydomain.com/users/users/login,但出现错误:在此服务器上找不到请求的地址“/users/users/login”。

在 UsersController.php 中似乎允许登录:protected function _setupAuth() {$this->Auth->allow('add', 'reset', 'verify', 'logout', 'view', 'reset_password', '登录');

插件已加载,因为蛋糕模式外壳直到它才起作用。

AppController 的前置过滤器:

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

 public function isAuthorized($user) {

     return true;
 }

function beforeFilter() {
    $this->Auth->allow('index');
            $this->set('logged_in', $this->Auth->loggedIn());
            $this->set('current_user', $this->Auth->user());
            $this->Auth->authorize = 'controller';
            $this->Auth->fields = array('username' => 'email', 'password' => 'passwd');
            $this->Auth->loginAction = array('plugin' => 'users', 'controller' => 'users', 'action' => 'login', 'admin' => false);
            $this->Auth->loginRedirect = '/';
            $this->Auth->logoutRedirect = '/';
            $this->Auth->authError = __('Sorry, but you need to login to access this location.', true);
            $this->Auth->loginError = __('Invalid e-mail / password combination.  Please try again', true);
            $this->Auth->autoRedirect = true;
            $this->Auth->userModel = 'User';
            $this->Auth->userScope = array('User.active' => 1);
            if ($this->Auth->user()) {
                $this->set('userData', $this->Auth->user());
            $this->set('isAuthorized', ($this->Auth->user('id') != ''));
    } 
}

}

我写的其他页面(不是插件)似乎工作正常。

它带有一个UsersAppController.php ...

我错过了什么?

非常感谢!

4

1 回答 1

1

As documentation, you must load the plugin on this way

CakePlugin::load('Users', array('routes' => true));

that means your routes must be

Router::connect('/users', array('plugin' => 'users', 'controller' => 'users'));
Router::connect('/users/index/*', array('plugin' => 'users', 'controller' => 'users'));
Router::connect('/users/:action/*', array('plugin' => 'users', 'controller' => 'users'));
Router::connect('/users/users/:action/*', array('plugin' => 'users', 'controller' => 'users'));
Router::connect('/login/*', array('plugin' => 'users', 'controller' => 'users', 'action' => 'login'));
Router::connect('/logout/*', array('plugin' => 'users', 'controller' => 'users', 'action' => 'logout'));
Router::connect('/register/*', array('plugin' => 'users', 'controller' => 'users', 'action' => 'add'));

Then for call login just go

/login

Best Regards

于 2013-02-24T03:36:01.063 回答