Php 对null error CodeIgniter上的成员函数的调用
请不要问我为什么有不止一个控制器:这是我老师想要的。 我有3个控制器:Api.php、Token.php和Apikey.php,其中Api.php是主要的控制器 问题:当我传入URL时: 从Api控制器加载令牌控制器似乎存在问题 错误:致命错误:调用成员函数generateToken时为null 我能做什么 API控制器:API.php Controller Token.phpPhp 对null error CodeIgniter上的成员函数的调用,php,codeigniter,locate,Php,Codeigniter,Locate,请不要问我为什么有不止一个控制器:这是我老师想要的。 我有3个控制器:Api.php、Token.php和Apikey.php,其中Api.php是主要的控制器 问题:当我传入URL时: 从Api控制器加载令牌控制器似乎存在问题 错误:致命错误:调用成员函数generateToken时为null 我能做什么 API控制器:API.php Controller Token.php 您也可以将令牌部分移动到模型中。您可以发布Api_模型的代码吗?可能是 class api extends CI_Co
您也可以将令牌部分移动到模型中。您可以发布Api_模型的代码吗?可能是
class api extends CI_Controller {
public function index()
{
parent::__construct();
$this->load->library("../controllers/Apikey.php");
$this->load->library("../controllers/Token.php");
}
public function registerUser ($username,$parola)
{
if ($this->isValidUserName($username) && $this->isValidPass($parola)) {
$this->load->library("../controllers/Token");
$id = $this->ApiModel->insertCredentials($username, md5($parola));
$this->Token->generateToken($id);
$this->ApiKey->generateApiKey($id);
$data['registered'] = 1;
$this->load->view('api', $data);
}
}
}
public function existsToken($token)
{
$arrayTokens = $this->ApiModel->getAllTokens();
if (in_array($token, $arrayTokens))
return existsToken(sha1($this->randomString())); //$this->isValidToken(sha1($this->randomString()));
return $token;
}
public function randomString() {
return intval(993432422 % rand());
}
public function generateToken($id_user)
{
$token = $this->existsToken(sha1($this->randomString()));
$date = $this->generateExpDate();
$result = $this->ApiModel->insertToken($token, $date, $id_user);
}