【问题标题】:Codeigniter /application/core/Frontend_Controller.php not found on live server在实时服务器上找不到 Codeigniter /application/core/Frontend_Controller.php
【发布时间】:2015-11-15 15:13:17
【问题描述】:

我在 Win 7 机器上的 XAMPP 开发了我的网站,它在 localhost 上运行完美。当我将它上传到实时服务器(linux)时。它开始向我显示此错误:

Fatal error: Class 'Frontend_Controller' not found in /home/acephm3/public_html/phenomesoft.com/application/controllers/Home.php on line 3

我已经检查并应用了所有我可以从谷歌获得的东西,但完全没有运气。

我使用的是 CI 3.0.3 版。

我已经设置$config['subclass_prefix'] = 'MY_';

/application/core中创建My_Controller.php如下:

class My_Controller extends CI_Controller {

    public function __construct() {
        parent::__construct();
        // Your own constructor code

    }

    public function send_mail($from, $from_name, $to, $subject, $message, $smtp, $debug) { 

        $this->load->library('email');

        if (!$smtp) {

            $this->email->from($from, $from_name);
            $this->email->to($to);

            $this->email->subject($subject);
            $this->email->message($message);

            if ( $this->email->send() ) {

                $this->session->set_flashdata('message', 'We\'ve received your message. Thank you for contacting us.');
                redirect('contact_us');

            } else {

                if ($debug) {
                    echo $this->email->print_debugger();
                }

                return false;

            }

        }

    }

}

包括:

include_once('Frontend_Controller.php');

/application/core/ 中创建Frontend_Controller.php 如下:

class Frontend_Controller extends My_Controller {

    public $data;

    public function __construct()
    {
        parent::__construct();
        // Your own constructor code

        $this->data = array();
    }

    public function _load_template($tpl, $data)
    {
        $this->load->view('frontend/includes/header', $data);
        $this->load->view('frontend/'.$tpl, $data);
        $this->load->view('frontend/includes/footer', $data);
    }

}

apllication/controllers/下创建了一个控制器Home.php

class Home extends Frontend_Controller {

    public function __construct() {
        parent::__construct();
        // Your own constructor code
    }

    public function index(){
        $this->_load_template('home', $this->data);
    }

}

在 routes.php 中设置$route['default_controller'] = 'home';

我还需要做什么?请再次注意,我在 localhost 上没有问题。

【问题讨论】:

标签: php codeigniter


【解决方案1】:

将此代码放在APPPATH . 'config.php'文件的末尾:

spl_autoload_register(function ($class) {
    if (substr($class,0,3) !== 'CI_') {
        if (file_exists($file = APPPATH . 'core/' . $class . '.php')) {
            include $file;
        }
    }
});

【讨论】:

  • 遇到 PHP 错误 严重性:通知消息:使用未定义的常量 EXT - 假定为 'EXT' 文件名:config/config.php 行号:526 回溯:文件:/home/acephm3/public_html/ phenomesoft.com/application/config/config.php 行:526 功能:_error_handler 文件:/home/acephm3/public_html/phenomesoft.com/application/controllers/Home.php 行:3 功能:spl_autoload_call 文件:/home/acephm3/ public_html/phenomesoft.com/index.php 行:292 功能:require_once
  • 立即尝试。我改了。
【解决方案2】:

变化:

include_once('Frontend_Controller.php');

收件人:

include_once( APPPATH.'core/Frontend_Controller.php' );

在家庭控制器中

【讨论】:

    【解决方案3】:

    我宁愿使用另一种方法,花了我一整天的时间来解决这个问题。

    1. application/core 文件夹中删除了 My_Controller.phpFrontend_Controller.php
    2. application/controllers 中创建了一个新控制器Application.php,并从CI_Controller 扩展了它。
    3. application/controllers 中创建了另一个控制器Frontend.php 并从Application 控制器扩展它(不要忘记在这个Frontend.php 控制器的顶部包含Application.php)。
    4. 现在在我的实际控制器Home.php 中包括顶部的Frontend.php 和来自Frontend 控制器的扩展家庭控制器。

    就是这样,现在每次您创建一个新的前端控制器时,都从Frontend 控制器扩展它。

    现在,我可以以同样的方式为我的后端控制器创建另一个控制器,并从中扩展我的所有后端控制器。

    享受..!!

    【讨论】:

      【解决方案4】:

      你可以尝试的另一种方法是

      文件名: MY_Controller.php

      <?php
      
      class MY_Controller extends CI_Controller {
         // Code Here
      }
      
      class Frontend_Controller extends MY_Controller {
          // Code here
      }
      

      前端控制器类与 MY_Controller.php 在同一个文件中

      家庭控制器

      文件名:Home.php

      <?php
      
      class Home extends Frontend_Controller {
      
      }
      

      【讨论】:

        猜你喜欢
        • 2017-09-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-15
        • 2017-06-22
        • 2016-04-18
        • 1970-01-01
        • 2013-10-16
        相关资源
        最近更新 更多