duanduo7400 2014-01-28 21:40
浏览 29
已采纳

更改了控制器加载位置,并且无法使用控制器中的任何功能

By default, as many of you probably know, codeigniter loads controllers from application/controllers (URI Segment 0). Well... I changed it so that it loads them fom application/modules/(URI Segment 0)/controllers/(URI Segment 1 / not set: URI Segment 0). Up to here it all works fine, but when I create a controller, I cannot use any of the default function as $this->load or etc... Example:

/**
* Home Controller Class
*/
class Home extends CI_Controller
{
    function __construct()
    {
        $this->load->database();
    }

    public function index()
    {
        echo "Testing...";
    }
}

This example would always result in an error:

Severity: Notice

Message: Undefined property: Home::$load

Filename: controllers/home.php

Line Number: 10

  • 写回答

1条回答 默认 最新

  • doufei1852 2014-01-28 22:50
    关注

    Well I don't know how you exactly changed the Controller location.

    But when you extend the CI_Controller, and you use a constructor method, you need to execute the parent's __construct() method at first, as follows:

    class Home extends CI_Controller
    {
        function __construct()
        {
            /* Execute the CI_Controller constructor */
            parent::__construct();
    
            $this->load->database();
        }
    }
    

    That's because your local constructor will be overriding the one in the parent controller class. So you need to manually call it.

    CodeIgniter Doc.

    Similar topics on SO:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号