简体   繁体   English

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

[英]Codeigniter displays a blank page in localhost

I have cloned an application from Bitbucket and when run the application through localhost, it displays a complete blank page. 我已经从Bitbucket克隆了一个应用程序,当通过localhost运行该应用程序时,它会显示一个完整的空白页。 When i downloaded a new codeigniter project from their website and run, it works fine and no issue. 当我从他们的网站下载一个新的codeigniter项目并运行时,它工作正常,没有问题。 But when i run this pulled project, it displays only blank page and no errors, everything was blank. 但是,当我运行此拉出的项目时,它仅显示空白页且没有错误,所有内容均为空白。

I am working in Ubuntu 16.04 with php version 7.0 我正在使用PHP 7.0Ubuntu 16.04中工作

The same project works fine in another system with same configuration as above said but when pulled in new in another system it doesn't work and displays a blank page. 同一项目在具有与上述相同配置的另一个系统中可以正常工作,但是在另一个系统中插入新项目时,它将不起作用并显示空白页。

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

Index.php file looks like, 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
}

The setting model is as follows, 设置模型如下,

<?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');
    }

}

What could be the error and kindly help to solve it. 错误可能是什么,请帮忙解决。

You need to check few things: 您需要检查几件事:

  • base_url
  • htaccess RewriteBase htaccess RewriteBase
  • permissions 权限
  • add error_reporting(1) in index.php and see what errors are reporting 在index.php中添加error_reporting(1)并查看正在报告的错误

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

Lot of things could be happening: 很多事情可能正在发生:

1) You must have an .htaccess file on your project root label (school-erp in this case). 1)您的项目根目录标签(在这种情况下为school-erp)必须具有.htaccess文件。 Open the .htaccess file and paste: 打开.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) Check your database.php file. 2)检查您的database.php文件。 You can find it in school-erp -> application -> config -> database.php 您可以在school-erp->应用程序->配置-> database.php中找到它

It is extremely important the same database name, password and user in this file and on your DBMS have the database created with these same parameters. 在此文件中使用相同的数据库名称,密码和用户非常重要,并且在DBMS上使用相同的参数创建数据库。 Remember codeigniter won't show any page if you have a config string on database.php that currently not match with what you have on your DBMS. 请记住,如果您在database.php上的配置字符串当前与DBMS上的配置字符串不匹配,则codeigniter不会显示任何页面。

3) Open a terminal as root user then change directory to the current path of your project which this way: 3)以root用户身份打开终端,然后通过以下方式将目录更改为项目的当前路径:

cd var/www/

Then you must give the necesary permisions to school-erp folder and all contained in it. 然后,您必须将必要的权限分配给school-erp文件夹,并将其全部包含在其中。 You can do it using this instruction: 您可以按照以下说明进行操作:

chmod 667 school-erp -R

Be carefull with the permision code you give to your files... chmod 777 isn't appropiate to production enviroments (I don't even use it on my localhost). 小心输入文件的渗透代码... chmod 777不适合生产环境(我甚至不在本地主机上使用它)。

4) Your current base_url will work if you have this folder structure (I will post it as a path): 4)如果您具有以下文件夹结构,则当前的base_url将起作用(我将其发布为路径):

var/www/school-erp

Why I say this? 我为什么这么说呢? because some server instalations come with an extra folder level. 因为某些服务器安装附带了额外的文件夹级别。 This folder is called normally "html". 该文件夹通常称为“ html”。 If this happens the path will be changed to: 如果发生这种情况,路径将更改为:

var/www/html/school-erp

Which means you will need to change your base_url too. 这意味着您也需要更改base_url。

5) Check in the other system the navigation bar of the browser when you enter to the index of the project (localhost/school-erp) if it doesn't appear "index.php" in the url it means that the server is rewriting the url so you will have to follow step 1) I posted on this answer plus turning on the a2enmod rewrite of apache server. 5)输入项目索引(localhost / school-erp)时,请在其他系统中检查浏览器的导航栏,如果该URL中未显示“ index.php”,则表示服务器正在重写网址,因此您将必须执行步骤1)我在此答案上发布并打开apache服务器的a2enmod重写。

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

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