Welcome Guest, Not a member yet? Register   Sign In
uri->segment returning false
#1

[eluser]Unknown[/eluser]
Hi

My controller name is "Events" and i have a function "viewdetails" inside it .

Now the problem is when i used $this->uri->segment(3) it return empty value. any have a solution .
here is my code:
link: http://localhost/myprj/index.php/events/viewdetails/2

if i am not wrong it ($this->uri->segment(3) ) should return 2 but it returns empty value. plz help

Thanks
#2

[eluser]Met[/eluser]
you have ommited your code

the following works:

Code:
<?php
class Events extends Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        // don't need anything here for this example
    }
    
    function viewdetails()
    {
        echo $this->uri->segment(3);
        $id = $this->uri->segment(3);
    }

    function viewdetails2($id=NULL)
    {
         //this also works      
        echo $id;
    }
}

URL - index.php/events/viewdetails/2

outputs 2.

note the "echo" - unless you are assigning the value to a variable, calling just $this->uri->segment(3) will not output anything on its own.
#3

[eluser]danmontgomery[/eluser]
or...

Code:
class Events extends Controller {
    
    function viewdetails($id)
    {
        echo $id;
    }

}




Theme © iAndrew 2016 - Forum software by © MyBB