【问题标题】:Helper not loading in Codeigniter?助手未在 Codeigniter 中加载?
【发布时间】:2015-05-20 11:53:57
【问题描述】:

这是我的简单控制器:

public function _construct()
{
    parent::_construct();
    $this->load->helper('url');
}


public function view($page = "index")
{

    if ( ! file_exists(APPPATH.'/views/truelove_view/'.$page.'.php'))
    {
        // Whoops, we don't have a page for that!
        show_404();
    } 

        $this->load->view('truelove_view/templates/header.php');
        $this->load->view('truelove_view/'.$page);   
        $this->load->view('truelove_view/templates/footer.php');    

当我包含 $this->load->helper('url');在 view() 中,代码可以工作,但是当我将它包含在上面的构造函数中时,它就不行了。如果我自动加载 url helper,它也可以工作。

有什么想法吗?

【问题讨论】:

    标签: php codeigniter helper


    【解决方案1】:

    在提供的代码中,您有 public function _construct() ,但它应该是 public function __construct()。需要加双下划线__

    【讨论】:

    • 太棒了,谢谢。这是一个下划线。我使用的是新的 IDE,有些字符看起来不一样。
    • Codelobster,从记事本++切换
    • 没试过,但听说过。我推荐 Netbeans
    【解决方案2】:

    使用数组加载你的助手:

    $this->load->helper( array('url') );
    

    【讨论】:

      猜你喜欢
      • 2012-12-30
      • 1970-01-01
      • 2011-01-12
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多