开发者

CodeIgniter: Can't Get My New Controller/View To Show

I am learning how to use codeIgniter as my php framework. I am reading through the documentation and watching the intro video and just generally following along with the first tutorial, but it's not working for me.

I have created a controller called "test.php" and a view called "test_view". The controller for this class is exactly like "welcome.php" and the view file just has some static html. However, when I go to index.php/test I get a 404 error.

I have also tried manipulating the original welcome files so that instead of calling a view it just echos "testing", yet I still see the开发者_StackOverflow original welcome message! I've tried clearing my browsing cash and refreshing, but to no avail.

Any suggestions? Thanks.

Edit: Here's the code for controllers/test.php

<?php 

class Test extends Controller {

        //Just trying to get it to echo test
    public function index()
    {
        echo "test";
        //$this->load->view('test_view');
    }
}
?>


Try looking at this page in the documentation - this might solve your problem.

This basically means you should try typing index.php?/test/ instead (notice the question-mark).


First of all, check the above link. Might be useful.

If not, then...

Try changing the default controller in the config file ('routes.php') to something else (probably, to 'test'), then try loading index.php. Just to test whether the whole system works (or not).

Check whether mod_rewrite is loaded (in your server .conf-file, if you're using Apache). Try using the latest build of the framework. AFAIK, the name of the controller class for now is "CI_Controller".

Finally, try removing the word 'public' before the declaration of the function. AFAIR, CI enable you to make private functions in controllers just by using prefix (which is set in the config file) at the beginning of the name of the function (thus making all the other functions public).

But most certainly the problem is with the mod_rewrite. If not, try debugging with die('Page found'); instead of echo - this will allow you to track possible redirects on the page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜