Codeigniter-扩展我自己的控制器 [英] Codeigniter - Extending my own controllers

查看:111
本文介绍了Codeigniter-扩展我自己的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以扩展自己的控制器。我已经在基于Web的应用程序上工作了一段时间,现在开始发现希望使用该应用程序的每个客户对它的工作方式都有不同的要求。我的想法是,如果我生成一个基本结构,然后扩展控制器以覆盖客户需要以不同方式工作的任何功能。

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


推荐答案

如果我没记错的话,那么您应该可以轻松做到这一点:

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

report2.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(){

    }

}

这篇关于Codeigniter-扩展我自己的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆