[SOLVED] $this->input->get: How to use it ? |
[eluser]sikko[/eluser]
hi all, I'm trying to get a GET string variable by the command: Code: $this->input->get('keywords', true); But when I set my form method to "get" (<form method="get"...) the url changes (what is totaly normal) and looks like this: /index.php/application/search?keywords=cars But since it changes, my controller function (named search) is not reached at all... and i have a 404 Page Not Found error. So my question is: is there a way to retrieve my form informations with get method ? As the function exists: I'm sure there is a way to do this... but how... Thanks, regards
[eluser]rogierb[/eluser]
Two questions when looking at your post arise Why is "application" in your url? index.php/search?something should do. Did you enable enable_query_strings in your config?
[eluser]sikko[/eluser]
Thank you for your quick reply My default controller is "Application" and the function search is in this controller Maybe should I create a "Search" controller ? My enable_query_strings was indeed set to FALSE. I've set it to TRUE but no result... Maybe the problem comes from my url as you noticed ?
[eluser]demogar[/eluser]
From the guide: Quote:If you change "enable_query_strings" to TRUE this feature will become active. Your controllers and functions will then be accessible using the "trigger" words you've set to invoke your controllers and methods: This means you have to use c=application&m=search&keywords=blablabla If I were you, I wouldnt use it this way, but anyways... it's up to you
[eluser]summery[/eluser]
Messing around with $_GET in CI is a lost cause. Instead, change your query strings to not use GET parameters, for example: Code: /index.php/application/search?keywords=cars Code: /index.php/search/keywords/cars Put the code to handle this in the search controller, in the keywords function, and get the "cars" parameter by calling: Code: $keywords = $uri->segment(3) Good luck!
[eluser]sikko[/eluser]
Quote:If I were you, I wouldnt use it this way, but anyways… it’s up to youWhy ? how would you use it ? Quote:/index.php/search/keywords/carsIs a nice url but isn't it bad practice to build my application in function of the url I want to obtain ? Can't I work around the second solution but in a nicer way by editing the routes file ? And if I want a keyword to be placed in the url, I am forced tu use javascript isn't it? Thanks for your help, see ya
[eluser]demogar[/eluser]
Well.. summery answered the first question: Quote:Messing around with $_GET in CI is a lost cause. About how i would use it? Code: # If you are looking by tags: If you will use base64_encode/decode (when you need it because you have 'special chars' in the url) you can check this out Yes, you can use routes for this. Just read the manual and thats all. Not neccesary, don't know why you will use javascript for this. Anchors exist and if you use [removed].href to modify the URL it will reload the window anyways. :]
[eluser]sikko[/eluser]
I mean when the user types some text into an input: the only way to transfer it to a link with href is to put it with javascript (or maybe I missed something...) About base64 encoding you're talking about: what about using uri_encode instead ? isn't it a better solution for this case ? So according to all of you, I should better forget the idea to use the global GET variables ? thanks
[eluser]Neeraj Kumar[/eluser]
I was about to post a new topic for this, glad someone asked it. Just a quick question, what would you do if you require to fetch lots of get variables? I am referring to Flickr API. I'll go insane if I have to create a URI containing 15 segments just for $_GET?
[eluser]Neeraj Kumar[/eluser]
I have found a solution, it's working great chek it out at: http://ellislab.com/forums/viewthread/47309/P30/#421002 |
Welcome Guest, Not a member yet? Register Sign In |