【问题标题】:Why My_controller doesn't work in linux hosting?为什么 My_controller 在 linux 主机中不起作用?
【发布时间】:2015-01-29 11:42:42
【问题描述】:

为我的网站创建 MY_controller 和 Frontend_controller 时出现空白页。

这里是控制器

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

我还在名为:Frontend_controller.php 的库中创建 Frontend_controller

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
 Class Frontend_controller extends MY_controller{ 
     public function __construct(){
         parent::__construct();
          echo'<script>alert()</script>'; 
     }
 }
?>

我还在Core文件夹中创建了MY_controller.php

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
Class MY_controller extends CI_controller{
    public $data = array(); 
    public function __construct() { 
        parent::__construct();  
    }
}

?>

为了调用所有类名,我还从一些教程中复制了这个函数并保存在 config.php 中

function __autoload($classname) {
    if (strpos($classname, 'CI_') !== 0) {
        $file = APPPATH . 'libraries/' . $classname . '.php';
        if (file_exists($file)) {
            @include_once($file);
        }
    }
}

最后我创建了 .Htaccess

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteCond %{ENV:REDIRECT_APP_PATH} !^$
RewriteRule ^(.*)$ - [E=APP_PATH:%{ENV:REDIRECT_APP_PATH}]

RewriteCond %{ENV:APP_PATH} ^$
RewriteRule ^(.*)$ - [E=APP_PATH:/$1]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>

我已经更改并测试了 URI 和 $config['base_url'] = ''; 的这个选项太

| 'AUTO'            Default - auto detects
| 'PATH_INFO'       Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'     Uses the REQUEST_URI
| 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'QUERY_STRING';

这里是查看welcome_message.php 在视图折叠中

HTML 换行

但它在我的本地主机上工作,为什么它不能在 linux 主机上工作** **我应该更换主机吗?

当我输入欢迎或登录到我的网站时,我得到空白页面

我真的很抱歉朋友我不知道该怎么做,因为我花了更多时间在上面。如果我不能,我会收到公司的警告信。

感谢帮助

【问题讨论】:

    标签: linux .htaccess codeigniter-2 codeigniter-url codeigniter-routing


    【解决方案1】:

    Linux 是区分大小写的操作系统,而 Windows 则不是。 你应该改变

    MY_controller to MY_Controller
    CI_controller to CI_Controller
    

    .Htaccess 也应该重命名为 .htaccess。 空 php 页面也称为“死亡白页”通常意味着您遇到了 php 致命错误。每当发生这种情况时,您都应该检查您的日志以获得详细的错误报告(或者如果您不在生产服务器中,则启用显示错误)。

    【讨论】:

      猜你喜欢
      • 2014-02-16
      • 1970-01-01
      • 2011-08-26
      • 1970-01-01
      • 1970-01-01
      • 2015-02-08
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      相关资源
      最近更新 更多