繁体   English   中英

Codeigniter在本地主机中显示空白页

[英]Codeigniter displays a blank page in localhost

我已经从Bitbucket克隆了一个应用程序,当通过localhost运行该应用程序时,它会显示一个完整的空白页。 当我从他们的网站下载一个新的codeigniter项目并运行时,它工作正常,没有问题。 但是,当我运行此拉出的项目时,它仅显示空白页且没有错误,所有内容均为空白。

我正在使用PHP 7.0Ubuntu 16.04中工作

同一项目在具有与上述相同配置的另一个系统中可以正常工作,但是在另一个系统中插入新项目时,它将不起作用并显示空白页。

基本网址为$config['base_url'] = 'http://localhost/school-erp/';

Index.php文件看起来像这样,

switch (ENVIRONMENT)
{
    case 'development':
        error_reporting(-1);
        ini_set('display_errors', 1);
    break;

    case 'testing':
    case 'production':
        ini_set('display_errors', 0);
        if (version_compare(PHP_VERSION, '5.3', '>='))
        {
            error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
        }
        else
        {
            error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
        }
    break;

    default:
        header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
        echo 'The application environment is not set correctly.';
        exit(1); // EXIT_ERROR
}

设置模型如下,

<?php

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

class Setting_model extends CI_Model {

    public function __construct() {
        parent::__construct();
    }

    /**
     * This funtion takes id as a parameter and will fetch the record.
     * If id is not provided, then it will fetch all the records form the table.
     * @param int $id
     * @return mixed
     */
    public function get($id = null) {

        $this->db->select('sch_settings.id,sch_settings.lang_id,sch_settings.is_rtl,sch_settings.timezone,
          sch_settings.name,sch_settings.email,sch_settings.phone,languages.language,
          sch_settings.address,sch_settings.dise_code,sch_settings.date_format,sch_settings.currency,sch_settings.currency_symbol,sch_settings.start_month,sch_settings.session_id,sch_settings.image,sessions.session'
        );
        $this->db->from('sch_settings');
        $this->db->join('sessions', 'sessions.id = sch_settings.session_id');
        $this->db->join('languages', 'languages.id = sch_settings.lang_id');
        if ($id != null) {
            $this->db->where('sch_settings.id', $id);
        } else {
            $this->db->order_by('sch_settings.id');
        }
        $query = $this->db->get();
        if ($id != null) {
            return $query->row_array();
        } else {
            return $query->result_array();
        }
    }

    /**
     * This function will delete the record based on the id
     * @param $id
     */
    public function remove($id) {
        $this->db->where('id', $id);
        $this->db->delete('sch_settings');
    }

    /**
     * This function will take the post data passed from the controller
     * If id is present, then it will do an update
     * else an insert. One function doing both add and edit.
     * @param $data
     */
    public function add($data) {
        if (isset($data['id'])) {
            $this->db->where('id', $data['id']);
            $this->db->update('sch_settings', $data);
        } else {
            $this->db->insert('sch_settings', $data);
            return $this->db->insert_id();
        }
    }

    public function getCurrentSession() {
        $session_result = $this->get();
        return $session_result[0]['session_id'];
    }

    public function getCurrentSessionName() {
        $session_result = $this->get();
        return $session_result[0]['session'];
    }

    public function getCurrentSchoolName() {
        $session_result = $this->get();
        return $session_result[0]['name'];
    }

    public function getStartMonth() {
        $session_result = $this->get();
        return $session_result[0]['start_month'];
    }

    public function getCurrentSessiondata() {
        $session_result = $this->get();
        return $session_result[0];
    }

    public function getDateYmd() {
        return date('Y-m-d');    }

    public function getDateDmy() {
        return date('d-m-Y');
    }

}

错误可能是什么,请帮忙解决。

您需要检查几件事:

  • base_url
  • htaccess RewriteBase
  • 权限
  • 在index.php中添加error_reporting(1)并查看正在报告的错误

case 'production':更改ini_set('display_errors', 0); ini_set('display_errors', 1); 在index.php中

很多事情可能正在发生:

1)您的项目根目录标签(在这种情况下为school-erp)必须具有.htaccess文件。 打开.htaccess文件并粘贴:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) school-erp/$1$2 [R=301,NE,L]

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

2)检查您的database.php文件。 您可以在school-erp->应用程序->配置-> database.php中找到它

在此文件中使用相同的数据库名称,密码和用户非常重要,并且在DBMS上使用相同的参数创建数据库。 请记住,如果您在database.php上的配置字符串当前与DBMS上的配置字符串不匹配,则codeigniter不会显示任何页面。

3)以root用户身份打开终端,然后通过以下方式将目录更改为项目的当前路径:

cd var/www/

然后,您必须将必要的权限分配给school-erp文件夹,并将其全部包含在其中。 您可以按照以下说明进行操作:

chmod 667 school-erp -R

小心输入文件的渗透代码... chmod 777不适合生产环境(我甚至不在本地主机上使用它)。

4)如果您具有以下文件夹结构,则当前的base_url将起作用(我将其发布为路径):

var/www/school-erp

我为什么这么说呢? 因为某些服务器安装附带了额外的文件夹级别。 该文件夹通常称为“ html”。 如果发生这种情况,路径将更改为:

var/www/html/school-erp

这意味着您也需要更改base_url。

5)输入项目索引(localhost / school-erp)时,请在其他系统中检查浏览器的导航栏,如果该URL中未显示“ index.php”,则表示服务器正在重写网址,因此您将必须执行步骤1)我在此答案上发布并打开apache服务器的a2enmod重写。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM