早点 发表于 2012-5-15 15:37:28

ci里想自己写个基类控制器

( ! ) Fatal error: Class 'MY_C' not found in D:\wamp\www\m.kkguo\application\controllers\show.php on line 8Call Stack#TimeMemoryFunctionLocation10.0003386848{main}()..\index.php:020.0010459872require_once( 'D:\wamp\www\m.kkguo\system\core\CodeIgniter.php' )..\index.php:20230.01401376512include( 'D:\wamp\www\m.kkguo\application\controllers\show.php' )..\CodeIgniter.php:250
报错!




首先我在application/core/ 中建了一个MY_C.php
里面代码如下:
<?php

/**
* Description of MY_C
* @author zaodian
* @version 2012-5-15 15:31:41
*/
class MY_C extends CI_Controller{
      function __construct()
    {
      parent::__construct();
    }

}

接着,我在application/controller/建了一个show.php
<?php

/**
* Description of show 新闻显示页
* @author zaodian
* @version 2012-5-14 11:49:40
*/
class Show extends MY_C{
    }


然后就报错了,说找不到.
是哪里有配置 没写对吗?


早点 发表于 2012-5-15 15:56:24

我是对着这手册里做的http://codeigniter.org.cn/user_guide/general/core_classes.html

米修 发表于 2012-5-15 16:18:53

名字一定要MY_Controller 类的名字和文件名同名

早点 发表于 2012-5-16 09:54:09

米修 发表于 2012-5-15 16:18 static/image/common/back.gif
名字一定要MY_Controller 类的名字和文件名同名

是同名的MY_C.php->class MY_C

城主 发表于 2012-7-18 18:39:08

还真不好用啊啊啊,没TP灵活

Just_alive 发表于 2012-7-18 20:01:09

require BASEPATH.'core/Controller.php';
        function &get_instance()
        {
                return CI_Controller::get_instance();
        }


        if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
        {
                require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
        }
CodeIgniter.php可以根据你的需求修改名字,不一定非要MY_Controller.php
页: [1]
查看完整版本: ci里想自己写个基类控制器