CodeIgniter not loading pages

2019-02-25 06:40发布

问题:

I have a web application developed using codeigniter and it worked fine in my previous server now I changed my server and when I am trying to run the web application there is nothing but a blank screen.

When I am trying to open the existing link http://mydomain.com/MyProject1/ It's a valid link but its showing me a blank page.

When I am trying to open another existing link mydomain.com/MyProject1/login/ This too a valid link but its displaying just a blank page.

Just for a test I tried some wrong link http://mydomain.com/MyProject1/test It's showing 404 error.

So, must be the code is running fine but pages are not being displayed. It's only showing blank page.

How can I fix this issue?

回答1:

Ok, turn displaying error in index.php (it's in the root) and change this if condition to something like:

if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL ^ E_NOTICE);
        break;

        case 'testing':
        case 'production':
            // error_reporting(0);
            error_reporting(E_ALL ^ E_NOTICE);
        break;

        default:
            exit('The application environment is not set correctly.');
    }
}

Then the errors show up.

Btw. try to set the correct htaccess path to your app if you are using it e.g. if on your localhost it was:

RewriteEngine On

RewriteBase /projects/mywebsite/

change it on server to:

RewriteEngine On

RewriteBase /

if you are not using subdomains etc., of course.

Btw. if you get an error like headers already sent or something like that, you will need to save your files as "utf-8 without BOM" instead just "utf-8". Or there might be some characters on the beginning of the file, which you need to delete in your text editor.

Check the files you are working with e.g. language files, views, controllers etc. and check them how are they encoded. If they are utf-8 change encoding to utf-8 without BOM. It can be done in almost every text editor like Notepad++ or Sublime. Then reupload these files to your server.



回答2:

Try with

http://mydomain.com/MyProject1/index.php/test

may be you are missing index.php,or else goto "config.php" and edit base url and index url as per your application like

$config['base_url'] = 'http://mydomain.com/MyProject1/';
$config['index_page'] = '';//Keep this as empty


回答3:

Try to echo the warnings, will let you know why the page is not loading. Go to your index.php page in the root of your CI folder and insert the following:

ini_set('display_errors', 1);


回答4:

If you have access to .htaccess file, on the first line paste the following code:

php_flag display_startup_errors on

php_flag display_errors on

php_flag html_errors on

Servers usually listens to htaccess php_flag better than ini_set php function. I had the same problem when I first installed Codeigniter.



回答5:

Check to see if you have enabled gzip in codeigniter. If you have gzip enabled and you are echoing stuff back then you might see blank page.

Try to use the output class of the codeigniter.

If it wasnt the case then try @MehrdadDastgir suggestion of using

ini_set('display_errors', 1);

and see what error its throwing.



标签: codeigniter