扩展CodeIgniter Controller时出错 [英] Error in extending CodeIgniter Controller

查看:97
本文介绍了扩展CodeIgniter Controller时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想扩展CodeIgniter控制器。我创建了 MY_Controller.php 文件,该文件的内容如下:

I am trying to extend the CodeIgniter controller. I have created MY_Controller.php file, the content of the file is as following:

<?php
class MY_Controller extends CI_Controller 
{ 
    function generate_key()
    {
        $n = rand(10e16, 10e20);
        return base_convert($n, 10, 36);
    }



现在我通过扩展 MY_Controller 而不是 CI_Controller 。以下是控制器的示例:

Now I create my controllers by extending MY_Controller instead of CI_Controller. Following is an example of a controller:

class Member extends MY_Controller
{
    public function index()
    {
    $this->load->view('welcome');
    }

我已将 MY_Controller.php 应用程序/ libraries / 文件夹中的c $ c>文件。但是当我加载应用程序,我得到的错误:

I have placed the MY_Controller.php file in the Application/libraries/ folder. But when I load the application, I get the error:

Fatal error: Class 'MY_Controller' not found in path\to\application\controllers\member.php

有人能告诉我我做错了什么?感谢。

Can someone tell me what i am doing wrong? Thanks.

编辑:我使用CodeIgniter 2.0.2

I'm using CodeIgniter 2.0.2

推荐答案

您需要在 application / core 中创建 MY_Controller.php 。我试过你的设置,并得到同样的问题。将自定义控制器移动到 core 解决了这个问题。

You need to create MY_Controller.php in application/core. I tried what you have setup and got the same problem. Moving the custom controller to core solved the problem.

希望它有帮助!

这篇关于扩展CodeIgniter Controller时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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