Welcome Guest, Not a member yet? Register   Sign In
Is URI segment 2 reserved?
#1

[eluser]kwhitaker[/eluser]
Hello all.

I'm writing a CI application that sends emails, so I have a controller called email, funny enough. Now this controller requires a parameter before it will generate a page, otherwise it kicks the user back to the index page.

My problem is that if I go to this url: www.example.com/index.php/mail/parameter I get a 404. Is segment 2 reserved? If so, how would you recommend that I get around this particular issue?

Code pasted here:
Code:
<?php

class Mail extends Controller {

    function Mail()
    {
        parent::Controller();

    }
    
    //Main index page of the mail list
    function index()
    {
        if(!$this->uri->segment(2))
        {
            //If they have not provided a link, kick them back to the index
            redirect('/videos/');
            exit();
        }
        else
        {
            echo "Hello World";
        }
        
    }
}
?>
#2

[eluser]xwero[/eluser]
The second segment is the method of the class. Routing solves this
Code:
$route['mail/(.+)'] = 'mail/index/$1';
#3

[eluser]kwhitaker[/eluser]
Thanks, that did the trick. Would you mind dissecting the code a bit so I know what exactly is going on?
#4

[eluser]Pascal Kriete[/eluser]
Normally CodeIgniter urls are www.example.com/controller/function/parameter1/param2/etc ..

Routes are nothing more than regular expressions. ".+" means one or more character, and the parentheses 'capture' that. So, the regular expression xwero is using says www.example.com/mail/anything should point to mail/index/anything .




Theme © iAndrew 2016 - Forum software by © MyBB