Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对null error CodeIgniter上的成员函数的调用_Php_Codeigniter_Locate - Fatal编程技术网

Php 对null error CodeIgniter上的成员函数的调用

Php 对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

请不要问我为什么有不止一个控制器:这是我老师想要的。 我有3个控制器:Api.php、Token.php和Apikey.php,其中Api.php是主要的控制器

问题:当我传入URL时:

从Api控制器加载令牌控制器似乎存在问题

错误:致命错误:调用成员函数generateToken时为null

我能做什么

API控制器:API.php

Controller Token.php


您也可以将令牌部分移动到模型中。您可以发布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);    
    }