Phil W.
Phil W.

Reputation: 91

CodeIgniter $this->load->view not working after version update

A site I am taking over was running really old versions of PHP (5.2.17) and CodeIgniter (2.2.0). I updated to PHP 7.0 - everything worked fine. I updated CodeIgniter to 3.1.4, following the manual and now I can't get $this->load->view to work (it shows a blank screen).

To make sure it wasn't a conflict with my existing code, I even replaced the /application directory with the packaged version from 3.1.4 and am trying the default page:

Controller: /application/controllers/Welcome.php

<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
    public function index() {
        echo 'Test';
        $this->load->view('welcome_message');
    }
}

View: /application/views/welcome_message.php:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter</title>
</head>
<body>

<div id="container">
    <h1>Welcome to CodeIgniter!</h1>
</div>

</body>
</html>

It will echo 'Test', but when I remove that line from the controller, it is just a blank screen. Where do I find the 'view' method to fiddle with it?

NOTE: I did update the config file according to the manual:

$config['base_url'] = 'https://example.com/'; 

I confirmed that it knows the file is there with another echo in the controller:

echo file_exists(APPPATH . 'views/welcome_message.php') ? 'exists' : 'does not exist';

UPDATE

I HAD NOT followed all of the instructions - as index.php in the root folder was not updated (I had only updated /system and /application). So VIEWPATH was an undefined constant. Updating this file immediately made it work.

Upvotes: 0

Views: 2462

Answers (1)

Phil W.
Phil W.

Reputation: 91

I HAD NOT followed all of the instructions - as index.php in the root folder was not updated (I had only updated /system and /application). So VIEWPATH was an undefined constant. Updating this file immediately made it work.

Upvotes: 0

Related Questions