Welcome Guest, Not a member yet? Register   Sign In
Why does uri->segment(); not work with me?
#1

[eluser]sungamer[/eluser]
Hello,

I am new in developing PHP with CI. Now I have a little problem with $this->uri->segment(3);. I enter this in my adressline
Quote:http://127.0.0.1/index.php/Media/index/1
Now I tried to extract the "1" from the URI with the given function. But it don't return anything...
Could you help me? Thanks!
#2

[eluser]GSV Sleeper Service[/eluser]
that capital M in Media may be causing problems...
#3

[eluser]sophistry[/eluser]
post code
#4

[eluser]sungamer[/eluser]
I think there is nothing interesting:
Code:
<?php
class test extends Controller {

    function test()
    {
        parent::Controller();
    }

    function index()
    {
        echo "ID=";
        echo $this->uri->segment(3);


    }
}

?>
#5

[eluser]metaltapimenye[/eluser]
try to reduce the "n" part of $this->uri->segment(n); try to replace it to '2'.. or '1', ooorr... try to print_r($this->uri->segment());
#6

[eluser]sungamer[/eluser]
I've tried this but it doesn't work.
Code:
print_r($this->uri->segment(1));
(Tried altought with 1,2,3)
#7

[eluser]xwero[/eluser]
why are you trying to use the media controller if you want the test controller? Or did you route the media segment to the test controller?

If you would do
Quote:http://127.0.0.1/index.php/test/index/1
You should see the desired result
#8

[eluser]sungamer[/eluser]
I used the http://127.0.0.1/index.php/test/index/1 URL, of course. I didn't want to change my media class, so I created the test class.
#9

[eluser]xwero[/eluser]
What do you get if you print $this->uri->segment_array()
#10

[eluser]sungamer[/eluser]
Code:
$uri=$this->uri->segment_array();
echo $uri;
Answer: "Array"
If I try something like "echo $uri[0]", I get an error.




Theme © iAndrew 2016 - Forum software by © MyBB