Unable to locate the specified class while calling another controller in codeigniter

冷暖自知 提交于 2020-01-05 08:20:43

问题


I have following code for controller Qprs

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Qprs extends CI_Controller {

    public function xyz()
    {
        //some code 
    }

}

below code used to call above controller from another controller

 $this->load->library('../controllers/Qprs');
 $this->Qprs->xyz();

but getting error:
Unable to locate the specified class Qprs.php
How to solve such error?


回答1:


Very simple way in codeigniter to call a method of one controller to other controller

1. Controller A 
   class A extends CI_Controller {

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

2. Controller B 

   class B extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
    }
    function custom_b()
    {
            require_once(APPPATH.'controllers/a.php'); //include controller
            $aObj = new a();  //create object 
            $aObj->custom_a(); //call function
    }
}


来源:https://stackoverflow.com/questions/44197660/unable-to-locate-the-specified-class-while-calling-another-controller-in-codeign

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!