CodeIgniter为所有控制器调用相同的函数 [英] CodeIgniter call same function for all controllers

查看:106
本文介绍了CodeIgniter为所有控制器调用相同的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,在那里我为一些控制器写的相同的功能。所以我想为所有控制器一个通用的功能。请帮助我,我坚持了这一点。

I'm developing an application, where the same function I'm writing for some controllers. So I wanted one common function for all controllers. Please help me out I've stucked up with this. The work would be more appreciated.

推荐答案

您可以创建 MY_Controller application / core

Class MY_Controller Extends CI_Controller{

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

    public function common(){
        // code here
    }
}

现在使用 MY_Controller 扩展每个类,函数
将可用于每个类



Now extend every class with MY_Controller and the function will be available for each class

Class Test Extends MY_Controller{

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

在网址中调用

http://localhost/app/test/common

这将工作。

这篇关于CodeIgniter为所有控制器调用相同的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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