CodeIgniter view doesn't load

I have an on-going CI v2.0.2 app that was coded by other developers.

I started off by creating a trial controller: `controllers/trial/trial.php'. The code in this controller is:

<h1>controller</h1>
<?php

class Trial extends CI_Controller {

    function index() {
        echo "this works";
        $this->load->view("trial/trial_view");
    }
}

And the view is in views/trial/trial_view.php. The view has a simple <p>this is the view</p> line.

Now when I visit the URL - http://localhost/ci/index.php/trial/trial all I get is the <h1> tag from the controller. If I remove that tag, nothing is seen, not even the echo statement.

The code base I was given is an exact replica of the app that is being used right now. I've doubly checked to make sure the folder structure is correct too.

What should be going on here? Any config options I should look at?

Update--------

I moved trial.php into the controllers folder, and trial_view.php into the views folder. Made the appropriate changes in the code too. But the result is still the same - only the h1 tag from the controller is displayed when I visit http://localhost/ci/index.php/trial

Upvotes: 0

Views: 3023

Answers (4)

Kenzo
Kenzo

Reputation: 3643

First off all, stop using the index method to do anything. If your class is called Trial, you need to do this with the index method:

public function index()
{
    $this->trial();
}

Then do everything under a method called trial.

Upvotes: 0

WatsMyName
WatsMyName

Reputation: 4478

try changing

function index() {
        echo "this works";
        $this->load->view("trial/trial_view");
    }

to

public function index() {
        echo "this works";
        $this->load->view("trial/trial_view");
    }

BTW try turning on error reporting and see if error is thrown

EDIT

BTW i tested with your code with same setting. It is working in my machine

Upvotes: 0

Ashok Raj
Ashok Raj

Reputation: 454

change it to,

 function index() {
    echo "this works";
    $this->load->view("trial/trial_view");
}

try putting trial.php outside trial folder inside controller folder, and get back what happens

Upvotes: 0

Roman Kolpak
Roman Kolpak

Reputation: 2022

your action is called index, while you're trying to access controller's trial action, which does not exist.

Upvotes: 2

Related Questions