I've the following controller class in my codeigniter and I want to load my library
and model
in constructor so that I can use it throughout my class.
class Cities extends CI_Controller{
public function __construct()
{
echo "a";
parent::__construct();
$this->load->library("cities");
$this->load->model("model_city");
}
public function getCities($type)
{
echo "ab";
if($type == "All" || $type == "*" )
{
$res = $this->model_city->getCities();
}
else
{
$res = $this->model_city->getPopularCities();
$data = mysql_fetch_assoc($res);
}
var_dump($res->results());
}
}
When I visit the URL , this code echoes "a"
several times and doesn't call the getCities
function. Here's the url I am visiting.
http://localhost/teleprintblog/index.php/Cities/getCities/All
What is the problem here ? Why is it calling the constructor
again and again without calling the getCities
function ?
you cant give a same name to a Controller and library class.
Here it is calling the controller class again and again thats why it is calling the controller again and again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.