How to change the URL in YII? - url

Ok, let me rephrase my question.
I have a website set up with URL in "path" format, and the api function works well.
Now I need to change only the URL of the api part in "get" format.
For example,
http://localhost/api/query/data?data=100294832
http://localhost/api/data/100294832
works.
api is a controller, data is a model. I have this in my main.conf,
array('api/view', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'GET'),
How could I do this? Should I create an action in api called query, and moved view function code there?
Thanks a lot!

The URL http://localhost/api/data/100294832 is the same as http://localhost/api/data/?id=100294832 by your route rule. It will work by default.

Related

Passing hidden params into url

I have a rails application in which I would like to generate a url based on a parameter, but for that parameter to be hidden from public view. So essentially working like a POST request but being able to be typed in like a GET request.
For example using a QR reader I could have the address as www.site.com/qr?lot_no=18007 but when a user scans the QR image it only shows www.site.com/qr but displays the results related to lot_no=18007.
Not sure if this is possible or not. But any help would be greatly appreciated.
If all you want to do is to prevent it from showing up in the address bar of the browser, you could use Rails.ajax to make the request dynamically through Javascript.
That will at least hide it from casual inspection, but there is no way to suppress the parameters from the query string on a GET completely, so anyone looking at the Networks tab in the browser (for example) would still see them.
Another alternative would be to encrypt the parameter value.
Maybe the Friendly id gem may be of help here
The following is an example of it's use is
http://example.com/states/washington
instead of:
http://example.com/states/4323454
This is not going to work with a post request as you mention though. It is a way of using a get request that would normally send an id in the params hash to retrieve existing records.
The gem can be found here https://github.com/norman/friendly_id
It is well maintained and up to date
Configure different route for public facing URL, the URL should include encrypted lot id as a path param.
routes.rb
get '/view_lot/:id' => 'QrCodesController#view_lot`, as: :public_view_lot
now in QrCodesController add action view_lot
def view_lot
encrypted_id = params[:id]
id = decrypt_it(encrypted_id)
#lot = Lot.find(id)
render "your_template"
end
in you QR code generation, pass URL to above action with encrypted id like public_view_lot_url(lot_id)

pass variable but not show in the url?

I want to pass a variable in my URL but not show it in the URL for SEO purposes
e.g www.mywebsite.com/Search?city=NYC should looks like www.mywebsite.com/Search and still be able to retrieve the value of "city" on the page.
Thanks
Simply use a POST request and you're done. However, is a common pratice to use GET request for search forms because the user can bookmark the url. Using POST, this isn't possible.
I just used Rewrite rules to accomplish this.

How to map an URL having querystring parameters in urlmapping.groovy?

I am new to Grails/Groovy. Please bear with me if this is a silly question.
I am trying to map an URL having querystring parameters in urlmapping.groovy, something like,
"/rest/employees?empno=123&dept=delivery"(controller:"employees", action="emp")
The values 123 and delivery are dynamic values. In other words, this could be anything that the user can use.
Apparently this syntax is not correct. What is the right way to achieve this?
Just leave /rest/employees"(controller:"employees", action="emp") and you'll get your query parameters as params.empno and params.dept in your action
#splix answer is correct. If you want to use a restfull url, you could do something like
"/rest/employees/$empno/$dept"
instead. Otherwise just leave out the part after "?" as said. In your controller you will still get params.empno and params.dept
Read more here

GWT Method GET, retrieve parameter

I have a gwt url like this
http://127.0.0.1:8888/BiddingSystem.html?gwt.codesvr=127.0.0.1:9997#ForumMessage=918
when I am doing this
Window.Location.getParameter("ForumMessage")
I am getting null??
By the way, I not getting the point why this ?gwt.codesvr=127.0.0.1:9997 in the url!!
To get the value of the URL fragment (the part after the #) call Window.Location.getHash(). This will return all of "ForumMessage=918".
getParameter() returns query parameters, not the URL fragment.
See here for more information about the parts of a URL.
The ?gwt.codesvr= part is needed to run in Development Mode.
Look at this topic GWT URL Parameters
Here is answer
url should be http://localhost:8080/?testing=abc#pg5 instead of http://localhost:8080/#pg5?testing=abc
and delete that part (?gwt.codesvr=127.0.0.1:9997 ) and run it in web mode. I think it will solve your problem

Grails g:paginate tag and custom URL

I am trying to use g:paginate in a shared template where depending on the controller, url changes e.g.
For my homepage url should be : mydomain[DOT]com/news/recent/(1..n)
For search Page: www[DOT]mydomain[DOT]com/search/query/"ipad apps"/filter/this month
and my g:paginate looks like this:
g:paginate controller=${customeController} action=${customAction} total:${total}
For the first case, I was able to provide controller as 'news' and action as 'recent' and mapped url /news/recent/$offset to my controller.
But for the search page, I am not able to achieve what I want to do. I have a URL mapping defined as /search/$filter**(controller:"search",action:"fetch")
$filter can be /query/"ipad apps"/filter/thismonth/filter/something/filter/somethingelse.
I want to be able to show the url as above rather than
?query="ipad apps"&filter=thismonth&filter=something&filter=somethingelse.
I believe I can pass all the parameters in params attribute of g:paginate but that will not give me pretty URL.
What would be the best way to achieve this? Please feel free to ask questions If i missed anything.Thanks in advance.
Ok. figured this out. Hope this helps someone.
Set ${customAction} ='' and this query string 'filter/thismonth/filter/something/filter/somethingelse' was passed with 'params' alltribute.
Thanks

Resources