Codeigniter - Extending my own controllers

牧云@^-^@ 提交于 2019-12-12 02:05:30

问题


I'd like to know if it's possible to extend my own controllers. I've been working on web-based applications for a while and I'm now starting to find each customer that wishes to use the application has different requirements of how it should work. My thoughts are that if I generate a base structure and then extend the controllers to override any of the functions that the customers require to work differently.

First of all, could you tell me if I'm on the correct track, and secondly, how do I go about extending my own controllers (if I can)? I've tried the usual:

Class Reports2 extends Reports { }

This doesn't work but I'm guessing it has something to do with the location of the file I'm trying to extend. My file structure is as follows:

Application
--->controllers
-------->control_panel
------------>reports.php

回答1:


If I am not mistaken then you should be able to easily do this:

reports2.php

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once(APPPATH.'controllers/control_panel/reports.php');

Class Reports2 extends Reports {

    public function __construct(){
        parent::_construct();
    }

    public function index(){

    }

}


来源:https://stackoverflow.com/questions/27910547/codeigniter-extending-my-own-controllers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!