【问题标题】:Codeigniter displays a blank page in localhostCodeigniter 在 localhost 中显示一个空白页面
【发布时间】:2018-06-07 02:43:17
【问题描述】:

我从 Bitbucket 克隆了一个应用程序,当通过 localhost 运行该应用程序时,它会显示一个完整的空白页面。 当我从他们的网站下载一个新的 codeigniter 项目并运行时,它工作正常,没有问题。 但是当我运行这个拉取的项目时,它只显示空白页,没有错误,一切都是空白的。

我在 Ubuntu 16.04 使用 php 版本 7.0

同样的项目在另一个系统中运行良好,配置与上述相同,但是当在另一个系统中拉入新的时它不起作用并显示一个空白页面。

基本网址是$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');
    }

}

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

【问题讨论】:

  • 你试过PHP 5+吗??
  • 请在 config/config.php 中检查您的“base_url”
  • @Star_Man Base 就像$config['base_url'] = 'http://localhost/school-erp/';
  • @prabhu,同样的事情在另一台包含 php 7 的计算机上也能正常工作。
  • 你检查了CodeIgniter和文件夹对index.php的权限吗?因为当我将项目从一台服务器转移到另一台服务器时,我遇到过这类问题。

标签: php codeigniter php-7


【解决方案1】:

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

【讨论】:

  • 它显示,Call to a member function num_rows() on boolean
  • 查看if($query !== FALSE &amp;&amp; $query-&gt;num_rows() &gt;0)
  • 只有当查询甚至无法执行时,SELECT 查询才会返回 FALSE 值。
  • 另一个文件出错,Message: Call to a member function result() on boolean Filename: /home/mani/dev/htdocs/school-erp/application/language/english/message_lang.php
  • 我认为您的查询不起作用并返回 FALSE。检查数据库设置
【解决方案2】:

你需要检查几件事:

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

【讨论】:

  • 基地就像$config['base_url'] = 'http://localhost/school-erp/';
  • OK 检查权限?
【解决方案3】:

可能会发生很多事情:

1) 您的项目根标签上必须有一个 .htaccess 文件(本例中为 school-erp)。打开 .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 -> application -> config -> 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”则表示服务器正在重写 url,所以你必须按照步骤 1)我在这个答案上发布,并打开 apache 服务器的 a2enmod 重写。

【讨论】:

    猜你喜欢
    • 2019-02-06
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    相关资源
    最近更新 更多