Controller Passing Varibles in URL |
[eluser]bdshan[/eluser]
From the user guide: Quote:If your URI contains more then two segments they will be passed to your function as parameters. I have a url that looks like this: index.php/lookup/stats/bdshan So I am trying to call the stats function of the lookup controller with a value of 'bdshan'. Simple enough. Here is my controller: Code: <?php I have the echo statement in there just for testing what is getting passed to the function. If I take it out, and uncomment of query code, I get this error: Quote:A PHP Error was encountered Why isn't my function getting the variable passed to in from the uri?
[eluser]hvalente13[/eluser]
Hi bdshan, If you are trying to call the function in other function of the controller, you have to call it like this: Code: function_name($this->uri->segment(3)) If you are trying to call the function as a page of the controller, you don't have to give it any parameters, as you can pass it through as uri->segment. Hope this helps
[eluser]bdshan[/eluser]
Maybe you miss understood me, I am trying to call the page like this: http://localhost/tieredracing/index.php/...ats/bdshan But I get this: Quote:A PHP Error was encountered From the errors I can tell that it is using the correct controller and function, but the 3rd uri segement is not getting passed to the function as the user guide states it should.
[eluser]bdshan[/eluser]
I got it working. I was reloading the uri library by accident. Once I removed it from autoload all is working as expected. Thanks
[eluser]hvalente13[/eluser]
Hi bdshan, As i've told you, you can access the http://localhost/tieredracing/index.php/...ats/bdshan by running function stats() as a page of the controller. In this case you don't have to give it any parameters... bdshan will be the uri->segment(3). So i'll do it like this: Code: <?php Tell me if is this work. Good luck
[eluser]Bl1nk[/eluser]
Ive been looking for a solution of this problem but I found this thread very the same with my problem. I installed new version of codeigniter 1.7.1 with xampp 1.7.2, I dont know if these are compatible. When I tried this URL: http://localhost/mostrag/index.php?/most...9156824269 It outputs an error of: Message: Missing argument 1, which I think that my code is correct. My class looks like this: class Mostrag extends Controller { // ... public function profile($id) { // ... } } I hope you can suggest what’s happening in my xampp and codeigniter. Im doing this in Windows Vista. Thanks. |
Welcome Guest, Not a member yet? Register Sign In |