【发布时间】:2015-10-21 18:43:50
【问题描述】:
我使用插件 BzUtils 插件创建令牌进行身份验证。 文件提升:
CakePlugin::load('BzUtils');
文件 AppController:
public function beforeFilter() {
$this->Auth->authenticate = array(
'Form' => array(
'fields' => array(
'username' => 'username',
'password' => 'password'
),
'userModel' => 'User',
'scope' => array(
'User.active' => 1,
)
),
'BzUtils.JwtToken' => array(
'fields' => array(
'username' => 'username',
'password' => 'password',
),
'header' => 'AuthToken',
'userModel' => 'User',
'scope' => array(
'User.active' => 1
)
)
);
RestUsersController 中的操作登录:
public function login() {
if ($this->Auth->login()) {
$user = $this->Auth->user();
$token = JWT::encode($user, Configure::read('Security.salt'));
$this->set('user', $user);
$this->set('token', $token);
$this->set('_serialize', array('user', 'token'));
} else {
throw new NotAcceptableException(__('Email or password is wrong.'));
}
}
网址:http://kcxcode1.dev/restusers/login
错误:致命错误:在第 42 行的 C:\xampp\htdocs\koreconx\app\Controller\RestUsersController.php 中找不到类“JWT”
【问题讨论】:
-
这是您使用的插件吗? github.com/burzum/cakephp-bz-utils
-
是的,我找到了不同的分支。在这个插件/分支中,静态函数
encode在哪里?你能找到它并在这里链接吗? -
我不明白..帮我修复错误..我用 cakephp2 做代码 api restful webservie 但我不能使用任何插件。
标签: php cakephp cakephp-2.0