我的核心课程My_head在codeigniter中找不到 [英] My core class My_head not found in codeigniter

查看:44
本文介绍了我的核心课程My_head在codeigniter中找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在codeigniter.in应用程序/ core中创建核心类,在名称为MY_head.php的文件中创建MY_head.php的代码为

i am trying to create core class in codeigniter.in application/core in create a file with the name of MY_head.php and the code of MY_head.php is

 class MY_head extends CI_Controller{

 public function __construct(){

     parent::__construct();
     }


  public function load_header(){
      //some code here


      }

 }

现在我正在尝试在我的控制器Practice.php中扩展此类。

Now i am trying to extend this class in my controller practice.php the code is

   class Practice extends MY_head{
   public function __construct(){

     parent::__construct();

      }
  function index(){


      }


  }

但是当我在浏览器中加载练习控制器时,它显示致命错误:找不到类'MY_head'。问题出在哪里?预先感谢
注意:$ config ['subclass_prefix'] ='MY _';

but when i load practice controller in browser it says Fatal error: Class 'MY_head' not found in. where the problem is? Thanks in advance Note : $config['subclass_prefix'] = 'MY_';

推荐答案

尝试将下面的函数放到下面在配置文件的底部

Try putting below function at the bottom of config file

/application/config/config.php

function __autoload($class)
{
    if(strpos($class, 'CI_') !== 0)
    {
        @include_once( APPPATH . 'core/'. $class . '.php' );
    }
}

并扩展控制器

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

class Practice extends MY_head
{
  public function __construct()
  {
     parent::__construct();
  }
}

或手动添加

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

// include the base class
require_once("application/core/MY_head.php");

//Extend the class 
class Practice extends MY_head
{
   public function __construct()
   {
      parent::__construct();
   }
}

?>

这篇关于我的核心课程My_head在codeigniter中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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