ID and $this->uri->segment(n) returning nothing

#1
[eluser]jstnjns[/eluser]
I can't seem to get the ID value from my URI segment or segment from URI lib to register.

Requested URI:
http://localhost/events/detail/1

Controller

Code:
class Events extends Controller {
    function Events()
        {
        ...
        }

    function detail($id)
    {
        echo $id;
        echo $this->uri->segment(3);
    }
}

I'm autoloading the URI library, but that shouldn't have anything to do with $id.. I'm getting these errors:

Missing argument 1 for Events::detail()

Undefined variable: id

Not sure what could be going on here. Don't have any non-standard $routes[].. Upgraded system to 1.7.1, but that didn't help. Can provide source if needed.

Thanks in advance!

#2
[eluser]jedd[/eluser]
Hi jstnjns and welcome to the CI forums.

What's uri->segment(2) and indeed (1) report back?

Could you paste your constructor - just to be sure that's okay.

Finally, your config.php entry for base_url ?

I think this is one of those types of problems that people sometimes by changing their config.php's 'uri_protocol' variable - cycling through them until they find one that works - but I've never had a problem with uri_protocol, so I don't know how effective that actually is.

#3
[eluser]pistolPete[/eluser]
[quote author="jstnjns" date="1252203625"]...
I'm autoloading the URI library ...[/quote]

You shouldn't:
User guide
Quote:Note: This class is initialized automatically by the system so there is no need to do it manually.

#4
[eluser]Herb[/eluser]
Ok, there seems to be some code missing in order to give you an answer to your problem.

Where is the detail method being called? Should be something like...
Code:
$some_variable = $this->uri->segment(3);
$data = detail($some_variable);
Otherwise, how does segment(3) get assigned to $id?

Or you might what to do it this way if you are calling it detail through the url:
Code:
http://yourwebsite.com/events/detail/1

class Events extends Controller {
    function Events()
        {
        ...
        }

    function detail()
    {
        $id = $this->uri->segment(3);
        echo $id;
        echo $this->uri->segment(3);
    }

#5
[eluser]jstnjns[/eluser]
SOLVED!

@jedd: They were also reporting back blank. The $config['base_url'] = 'http://localhost/'.

@herb: The $id value was being assigned in the URI (http://localhost/events/detail/34, 34 would be $id).

-------------------------

@pistolPete: You are right, and after un-autoloading, it works just great! Thanks! Guess I need to take a closer look into the User Guide at these sorts of things.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.