Cannot find the specified class when calling another controller in codeigniter

I have the following code for Qprs controller

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

class Qprs extends CI_Controller {

    public function xyz()
    {
        //some code 
    }

}

      

below is the code used to call the above controller from another controller

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

      

but the error is:
Could not find the specified class Qprs.php
 How to solve such an error?

+1


source to share


1 answer


A very simple way in codeigniter to call a method of one controller to another 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
    }
}

      

0


source







All Articles