繁体   English   中英

Codeigniter __construct在控制器中被多次调用

[英]Codeigniter __construct being called multiple times in controller

我在codeigniter中具有以下控制器类,并且我想在构造函数中加载我的librarymodel ,以便可以在整个类中使用它。

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());
}
}

当我访问URL时,此代码多次回显"a" ,并且不调用getCities函数。 这是我要访问的网址。

http://localhost/teleprintblog/index.php/Cities/getCities/All

这里有什么问题 ? 为什么调用constructor连连,而不调用getCities功能?

您不能给Controller和库类使用相同的名称。

在这里它一次又一次地调用控制器类,这就是为什么它一次又一次地调用控制器的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM