问题
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