Welcome Guest, Not a member yet? Register   Sign In
Question about routing.
#1

[eluser]dreamer111[/eluser]
Silly question. here is my contoller, controller_f_blog.php:

Code:
<?php
class Controller_f_blog extends Controller {
    function __construct() {
        parent::Controller();
    }

    function Index() {
           echo 'index page....';
    }


    function Comments() {
          echo 'comments page.....';
    }
}
?>


Here is the sample routing part:
Code:
$route['blog'] = "controller_f_blog";

So. When I enter localhost/ci/blog/comments - I expect function comments to run automatically - right or wrong? because I'm getting 404 errorr.

However - localhost/ci/blog/ runs default index function just fine. Why comments function doesn't work automatically. Should I specify it in config/routes.php? cuz I thought that corresponding method should run by itself. What am I doing wrong?
#2

[eluser]JanDoToDo[/eluser]
If you look through the CI config folder for the file which contains "default_controller" it sets which function is automatically run when a controller is loaded.. (Oh wrong answer..)

The right answer is you have set the route up to "blog" not "blog with comments" So it only sends the person to controller_f_blog with no function:

$route['blog/(:any)'] = "controller_f_blog/$1";
#3

[eluser]dreamer111[/eluser]
thanks for reply.
I've changed my routes.php entry to suggested - unfortunately I still have the same issue - only index function works. I get 404 errorrs when i try to access comments.
I'll try to configure CI from scratch and try again. will see what happens.
#4

[eluser]OliverHR[/eluser]
So weird, I had never tried this before...¿Is this a bug????

Anyway you must use in: config/routes.php

Code:
$route['blog'] = 'Controller_f_blog';
$route['blog/(:any)'] = 'Controller_f_blog/$1';
#5

[eluser]dreamer111[/eluser]
I've changed controller name and file name so they don't use underscores and it worked....

wtf Smile

I thought i can use underscores in filenames as well as controller names.
#6

[eluser]dreamer111[/eluser]
could there be a problem if I have apache, mysql, php on my windows 7 instead of linux?




Theme © iAndrew 2016 - Forum software by © MyBB