thinkphp-jump
thinkphp-jump copied to clipboard
Call to a member function isJson() on null
6.0.2各种报错::: 1、Call to a member function isJson() on null 2、Call to a member function isAjax() on null 3、....
6.0.2各种报错::: 1、Call to a member function isJson() on null 2、Call to a member function isAjax() on null 3、....
怎么用的?怎么可能各种报错
安装首页安装教程来的 先composer安装,然后在基类use引入,然后在自定义控制器集成基类,然后使用$this->error(),success();然后就报错。代码如下:
基类:
use \liliuwei\think\Jump;
控制器: `use app\BaseController; use think\facade\Session;
class Base extends BaseController { public function index(){}
// 检查用户是否登录
public function isLogin(){
$uid = Session::get('uid');
dump($uid);
if(empty($uid)) {
return $this->error('xxx');
}
}`
安装首页安装教程来的 先composer安装,然后在基类use引入,然后在自定义控制器集成基类,然后使用$this->error(),success();然后就报错。代码如下: 基类:
use \liliuwei\think\Jump;
控制器: `use app\BaseController; use think\facade\Session;
class Base extends BaseController { public function index(){}
// 检查用户是否登录 public function isLogin(){ $uid = Session::get('uid'); dump($uid); if(empty($uid)) { return $this->error('xxx'); } }`
不存在你说的问题,其他人都是正常的
6.0.2各种报错::: 1、Call to a member function isJson() on null 2、Call to a member function isAjax() on null 3、....
同样的问题
贴代码
我也是同样的问题 thinkphp6.0.5
定义一个方法: public function verification($jwt) {
try {
throw new \think\Exception('access_token已弃用!');
$decoded = JWT::decode($jwt.'123', $this->key, ['HS256']); //HS256方式,这里要和签发的时候对应
$arr = (array)$decoded;
$data = (array)$arr['data'];
if (!Cache::get('admin_' . $data['admin_uid'])) { //手动退出过的情况,使用未过期的旧的access_token
throw new \think\Exception('access_token已弃用!');
}
return $arr;
} catch (\Firebase\JWT\SignatureInvalidException $e) { //签名不正确
$this->error('签名不正确,非法令牌', NULL, [
'code' => Config::get('errormsg.illegal_token'),
'data' => []
]);
} catch (\Firebase\JWT\BeforeValidException $e) { // 签名在某个时间点之后才能用
$this->error('令牌还未生效', NULL, [
'code' => Config::get('errormsg.token_ineffective'),
'data' => []
]);
} catch (\Firebase\JWT\ExpiredException $e) { // token过期
$this->error('令牌已过期', NULL, [
'code' => Config::get('errormsg.token_expired'),
'data' => []
]);
} catch (\think\Exception $e) { //其他错误
$this->error($e->getMessage(), NULL, [
'code' => Config::get('errormsg.error'),
'data' => []
]);
}
}
在应用中间件中调用: $JwtToken = new JwtToken(); $JwtToken->verification($access_token); 报错:Call to a member function isJson() on null 或者是 Call to a member function isAjax() on null
定义一个方法: 公共功能验证($ jwt) {
try { throw new \think\Exception('access_token已弃用!'); $decoded = JWT::decode($jwt.'123', $this->key, ['HS256']); //HS256方式,这里要和签发的时候对应 $arr = (array)$decoded; $data = (array)$arr['data']; if (!Cache::get('admin_' . $data['admin_uid'])) { //手动退出过的情况,使用未过期的旧的access_token throw new \think\Exception('access_token已弃用!'); } return $arr; } catch (\Firebase\JWT\SignatureInvalidException $e) { //签名不正确 $this->error('签名不正确,非法令牌', NULL, [ 'code' => Config::get('errormsg.illegal_token'), 'data' => [] ]); } catch (\Firebase\JWT\BeforeValidException $e) { // 签名在某个时间点之后才能用 $this->error('令牌还未生效', NULL, [ 'code' => Config::get('errormsg.token_ineffective'), 'data' => [] ]); } catch (\Firebase\JWT\ExpiredException $e) { // token过期 $this->error('令牌已过期', NULL, [ 'code' => Config::get('errormsg.token_expired'), 'data' => [] ]); } catch (\think\Exception $e) { //其他错误 $this->error($e->getMessage(), NULL, [ 'code' => Config::get('errormsg.error'), 'data' => [] ]); } }
在应用中间件中调用: $ JwtToken = new JwtToken(); $ JwtToken-> verification($ access_token); 报错:在null上调用成员函数isJson()或在null上调用成员函数isAjax()
我想请问下你是怎么解决这么问题的
已在BaseControoler中use \liliuwei\think\Jump;还是跳转报错,请问下到底是何原因? #0 [0]Error in Jump.php line 163 Call to a member function isJson() on null }
/**
* 获取当前的response 输出类型
* @access protected
* @return string
*/
protected function getResponseType()
{
return $this->request->isJson() || $this->request->isAjax() ? 'json' : 'html';
}
}
控制器中要使用 public function initialize(){ 。。。。 }
用__construct就会报错。
是的,项目做一大半了。用到__construct的都报错了不能调用这个插件了。有大神解决吗?
是的,项目做一大半了。用到__construct的都报错了不能调用这个插件了。有大神解决吗?
建议再熟悉一下trait 的用法,了解一下优先级和冲突的解决
手册地址:https://www.php.net/manual/zh/language.oop5.traits.php
是的,项目做一大半了。用到__construct的都报错了不能调用这个插件了。有大神解决吗?
可以考虑用框架带的initialize() 代替 __construct来实现一些功能
use \liliuwei\think\Jump;
class Auth
{
use Jump
public function __construct()
{ }
public function checkNode()
{
$this->error('请先登录', url('admin/login/index'));
}
ThinkPHP V6.0.12LTS
同样出现了此问题,求解