Welcome Guest, Not a member yet? Register   Sign In
getting values from urls
#1

[eluser]Vitsaus[/eluser]
Hi,

I'm having troubles to get values from urls. I can get the name of the controller etc but if i try to do something like http://mysite.com/controller/1, it gives me errors.

- Htaccess works, mod_rewrite works, everything should be ok there.
- print $this->uri->rsegment(1); results correctly "controller" but if I try print $this->uri->rsegment(2); and try to get a value, I get a following error:

Code:
404 Page Not Found

The page you requested was not found.

So all it does is, that it assumes it as a some kind of controller, not variable value like index.php?id=1! I want it to be a value that I can pick up from URL. How to achieve that?

However, is this wrong way to do it at all, should I use Session or something like that to solve this problem?

Thanks.
#2

[eluser]sinvos[/eluser]
Open your config file change the following values.

$config['uri_protocal'] = "PATH_INFO"; //resolves page not found
$config['enable_query_strings'] = TRUE;

This resolved my issue with passing values in URL. Hope it solves your problem.
#3

[eluser]Vitsaus[/eluser]
Nope, still not working the way it should. Gotta be something else, that I just haven't spotted yet.
#4

[eluser]sinvos[/eluser]
did you try grabbing the info by using $_GET?
foreach ($_GET as $key => $value)
{
if ($key=='id') $id=$value;
}
#5

[eluser]Vitsaus[/eluser]
Ha,

managed to get it work. I was using the controllers the way they should not have been used in this case. It seems that I can only take a value when I use http://example.com/main/news/thisIsValue. If I use http://example.com/main/thisIsValue, it does not work same way.

It's certainly not so easy to move away from procedural coding to oop(mvc) styled codin Smile.
#6

[eluser]xwero[/eluser]
It has nothing to do with OOP or MVC. It's the common way frameworks identify the controller and its method.

If you want to use one segment, you use routing
Code:
$route['main/(\d+)'] = 'main/news/$1';




Theme © iAndrew 2016 - Forum software by © MyBB