0
votes

I am new to coding and have fallen in love with codeigniter and recently moved from a wamp server to a LAMP server. I've extracted codeigniter into /var/www/ and set the root directory of the host in apache. I can see the codeigniter welcome page, however if I change the default controller in config.php to my controller and load this controller:

    class Site extends CI_Controller    {

public function index() {
    $this->load->view('home_view');
}
}

I get this text in my browser:

$this -> load -> view ('home_view'); }}

The only line of my index function as well as a codeigniter generated 404 error below it. base_url() and default controller are set, codeigniter welcome page works fine, but my page does not. Does anyone have an idea as to why? Your help is very much appreciated.

1
do you have <?php at the top of the page? - Scriptable
reset everything back so you can see the welcome page. now try adding another method to the welcome controller and see if that works. And the default controller is set in config/routes.php NOT config.php - cartalot
@Scriptable yes that code is closed in php tags - Philip Graham
@cartalot I used a method to call the home_view and a blank page loaded, but no 404 error. Weird. Then I tried to echo 'hello' from the controller, and nothing happened. - Philip Graham

1 Answers

0
votes

Make sure your controller is inside application/controllers and the name is site.php

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

class Site extends CI_Controller {

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

    public function index()
    {
        $this->load->view('home_view');
    }

}