无法加载库代码Igniter遇到无法加载类的错误:

时间:2015-12-15 18:16:34

标签: php codeigniter

我已经在Stack上尝试了所有可能的解决方案以及关于CI用户指南的创建库指南,请告诉我我做错了什么。

我试图将api调用库Convioapi与我的登录类连接,请参阅下文。 我已经尝试在构造中加载库

我仍然遇到同样的错误:

  

遇到错误

     

无法加载请求的类:Convioapi

class Convioapi
{
    //public assigned variables
    public $host = 'qwerqwerqwerqwer';
    public $short_name = 'qwerqwerqwerqw';
    public $api_key = 'qwerqwerqwerqwerwe';
    public $v = '123412341';
    public $response_format = 'json';

    //private variables
    private $__method;
    private $__methodParams = array();
    private $__servlet;

    public function __construct($data = array())
    {
        $this->CI =& get_instance();

        if (count($data) > 0 ){
            foreach ($data as $key )
            {
                $login_name = $data['username'];
                $login_password = $data['password']; 
                $servletMethod = $data['servletMethod'];
                }    
            }else{
                $login_name = NULL;
                $login_password = NULL;
                $servletMethod;
            }


        $this->call($servletMethod);
    }

    private function __getPostData()
    {
        $response_format = $this->response_format;
        if ($this->response_format == 'php') $response_format = 'json';
        $baseData   = http_build_query(array('v'=>$this->v,'api_key'=>$this->api_key,'response_format'=>$response_format,'login_name'=>$this->login_name,'login_password'=>$this->login_password,'method'=>$this->__method));
        $methodData = http_build_query($this->__methodParams);
        return sprintf('%s&%s', $baseData, $methodData);
    }

    private function __makeCall()
    {
        $url  = $this->__getUrl();
        $post = $this->__getPostData();

        // Here is where we check for cURL. If we don't find it we make a fopen call...
        if (function_exists('curl_exec') === FALSE)
        {
            $context = stream_context_create(array('http'=>array('method'=>'POST','content'=>$post)));
            $fp = @fopen($url, 'rb', FALSE, $context);
            $response = @stream_get_contents($fp);
            @fclose($fp);

            if ($response == '') $response = sprintf("The server returned no useable data. This likely points to a NULL result. Try installing php-curl for better error handling.\n");
        }

        else
        {
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_POST, TRUE);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
            $response = curl_exec($curl);

            if ($response == '') $response = sprintf("cURL Error %s: %s\n", curl_errno($curl), curl_error($curl));

            curl_close($curl);
        }

        if ($this->response_format == 'php') $response = json_decode($response);

        return $response;
    }

    private function __getUrl()
    {
        return sprintf('https://%s/%s/site/%s', $this->host, $this->short_name, $this->__servlet);
    }

    public function call($servletMethod, $params = NULL)
    {
        $this->__servlet = array_shift(explode('_', $servletMethod));
        $this->__method  = array_pop(explode('_', $servletMethod));
        if ($params !== NULL) $this->__methodParams = $params;
        return $this->__makeCall();
    }

}

我已自动加载此文件,也称为

$autoload['libraries'] = array( 'database', 'Session', 'Convioapi');

这是我的登录课程,我计划在其中执行所有登录功能

<?php

if(!defined('BASEPATH'))exit('不允许直接访问脚本');

class Login extends CI_Controller {

    public function __construct()
    {
        parent::__construct();


        $this->load->helper(array('form'));
            //Load form helper
        $this->load->helper('form');

        //Load form_validation
        $this->load->library('form_validation');

        //Load session Library
        $this->load->library('Session');

    }


    public function index()
    {
        $this->load->view('login');
    }

    public function userLogin(){
    //form validation set rules

    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');

    if ($this->form_validation->run() == false){
    if(isset($this->session->userdata['logged_in'])){
        $this->load->view('memberArea'); //member search area
        }else{
        $this->load->view('login'); //login 
        }
    } else {

        $userdata = array(
            'username' => $this->input->post('username'),
            'password' => $this->input->post('password'),
            'servletMethod'=> 'SRConsAPI_login'
            );

//              $this->load->library('ConvioOpenAPI', $data);       
        /*
        check if user exist in convio database using API 
        if true add session usrname to session data array
        and set userdata logged in $session data
        lastly allow user to enter member search view
        */      
        $groupdata = array(
            'username' => $this->input->post('username'),
            'password' => $this->input->post('password'),
            'servletMethod'=> 'SRConsAPI_getUserGroups'
            );

        $jsonUserString = $this->load->library('Convioapi', $userdata);
        $jsongroupString = $this->load->library('Convioapi', $groupdata);

        $arrayUser = json_decode($jsonUserString, true);
        $arrayGroup = json_decode($jsongroupString, true);

        if (!array_key_exists('errorResponse', $arrayUser) && 
            !array_key_exists('errorResponse', $arrayGroup))
        {

            if ( array_key_exists('cons_id', $arrayUser['loginResponse']) && array_key_exists('group', $arrayGroup['getConsGroupsResponse'])) {

                if ($arrayUser['loginResponse']['cons_id'] && $arrayUser['getConsGroupsResponse']['group']['id'] == '104'){
                    echo 'good';
                    //user goood
                }else{
                    echo 'bad';
                    //user bad
                }

            }else{

                return false;
}

        }else{
            return false;
        }

        }
    }

    public function logout(){

        //removing session data
        $sess_array = array(

            'username' => ''
        );
        $this->session->unset_userdata('logged in', $sess_array);
        $data['message_display'] = 'Successfullu Logged out';
        $this->load->view('login_form', $data);
    }

}

/ *文件结尾login.php / / 位置:./ application / controllers / login.php /

1 个答案:

答案 0 :(得分:0)

1 - 在system/libraries文件夹下添加库文件 2 - 确保首字母大写(文件名和类名) 3 - 然后编辑autoload.php的相关行,如下所示:
$autoload['libraries'] = array( 'database', 'session', 'convioapi');

它必须完美运作!