0

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

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

Well, the controller named trial.php is within a folder named trial. That's how I'm accessing the controller - http://localhost/ci/index.php/sub-directory-within-controller/controller. Is this incorrect?
check out CI URI routing documentation, your url is using this pattern index.php/controller/action/param, in your case it should be index.php/trial/index or simply index.php/trial, since the index is a default action to be loaded when no action specified
I've updated the question - now the trial.php controller lies within the controllers folder. Likewise, I've moved the view and updated the code to reflect these changes. However, its still the same.
0

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

5 Comments

Sorry about that. The view is loaded as $this->load->view("trial/trial_view"); I've updated the question to reflect this.
did u restrict anything with htaccess/routing config?
Well, routes.php says this much - $route['default_controller'] = "welcome"; $route['404_override'] = ''; And the .htaccess in the application folder has deny from all.
try putting trial.php outside trial folder inside controller folder, and get back what happends
Yes.. I just tried that. And the result is the same - only the h1 from the controller is shown. The url right now is http://localhost/ci/index.php/trial/
0

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

8 Comments

any function is public by default when no access specifier is given.
@rawry, I know just incase. Like, the code is working perfectly in my machine according to his settings, controllers/trial/trial.php and views/trial/trial_view.php
I set up a clean CI v2.1.2 project, and was able to access a controller from within a sub-directory, and the view too showed its output. So the issue must lie with the configuration of the initial project. Any pointers where I should look at?
@HrishikeshChoudhari, can you download version 2.0.2, make a clean install and try if that work?? There have been lots of changes from 2.0.2 to version 2.1.2. Download 2.0.2 Version downloads.codeigniter.com/reactor/CodeIgniter_2.0.2.zip
@HrishikeshChoudhari This way you can confirm if its problem in version 2.0.2 or in a configuration somewhere in your old app.
|
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.