我击中了一个难题。
我已经安装了https://github.com/firebase/php-jwt,在我的第三_party文件夹中,该库带有作曲家。
如何从具有某些参数的模型或控制器中使用JWT::encode
?
例如,我想从控制器调用getToken($parameters)
模型,然后在该JWT库中加载该模型。我已经搜索了很多,但是我的PHP知识似乎有限。
确定解决。
您要做的是安装Third_party库。在下面的图书馆文件夹中的新文件中自动加载。
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
{
require_once(APPPATH . 'third_party/firebase-jwt/vendor/autoload.php');
require_once(APPPATH . 'third_party/firebase-jwt/start.php');
}
class Firebasetoken {
function __construct($permissions = false) {
$this->codeigniter_instance =& get_instance();
$this->theToken = buildToken($permissions);
}
function get_firebase_token(){
return $this->theToken;
}
在您的start.php加载中,因为命名空间和CI显然表现不佳。
<?php
require_once 'jwt/src/BeforeValidException.php';
require_once 'jwt/src/ExpiredException.php';
require_once 'jwt/src/SignatureInvalidException.php';
require_once 'jwt/src/JWT.php';
use FirebaseJWTJWT;
function buildToken($permissions){
//add example from jwt lib in here
}
然后这样称呼。
$this->load->library('FirebaseToken', $permissions);
$token = $this->firebasetoken->get_firebase_token();
瞧。希望它能节省某人的时间。