cakePHP 2.0 cakedc用户插件 - 似乎已安装但无法访问

时间:2013-01-02 03:36:25

标签: plugins cakephp-2.0 cakedc

我知道我应该可以通过[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','login');

加载了

插件,因为cake schema shell在它之前不起作用。

AppController的beforefilter:

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 ...

我错过了什么?

非常感谢!

1 个答案:

答案 0 :(得分:1)

作为文档,您必须以这种方式加载插件

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

这意味着您的路线必须

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

然后拨打电话登录

/login

最好的问候