I'm using a simple extension, which displays a list of properties from a domainobject in a f:select. After using the dropdown the form redirects to an controller action and the repository gets all records according to the choosen property by argument.
<f:form class="filter-select" name="filter-select" method="post" action="showByProperty" pageUid="{settings.detailShowByProperty}">
<f:form.select name="filter-form" options="{properties}" optionLabelField="title" optionValueField="uid" prependOptionLabel="Please choose..." prependOptionValue="0" />
<button>
Show matching records
</button>
How can i use route enhancers with select field to create an url like:
http:www.mysite.com/detailpage/property
Especially i dont know how to append the property / argument.
Thanks in advance!
This wont't work. Sending an form is completly handled by client / browser. Only option is to send the form to another action which creates an redirect with uriBuilder and form data as parameters to get an speaking url.
Related
Good evening, I'm working with Google Custom Search Engine: https://cse.google.it/cse/ and I need to add, only for some URLs (in total 10 URLs) a parameter at the end of each search results URL. For example: if the domain is www.dominio-test.com then the URL to show is www.dominio-test.com/123456 the CSE searches on the web without restriction.
The code I use is the following:
<script async src = "https://cse.google.com/cse.js cx=014431187084467459449:v2cmjgvgjr0"> </script>
<div class = "gcse-search"> </div>
I thought of proceeding with reading the DOM with getElementsByClassName (), extracting the content and adding it to a variable, at this point add the if / else / replace controls and output again.
But I don't know how to proceed, can you please support me?
Thanks and good job
Search Element callbacks might work for you: https://developers.google.com/custom-search/docs/element#callbacks
I'm trying to add just one parameter to my postback url to a custom partner. What I need is to pass a Click Id that advertiser will put into link. For example hi'll make traffic to this link - cq8y2.app.link/?click_id=777 how could i map that click_id parameter to postback url?
You should use a macro to extract the click_id value. Append to the postback URL as a GET-parameter the following:
?clickid=${ (last_attributed_touch_data.~click_id)! }
I am trying to pass array of values as parameter to controller action in YII Framework,
My URL is like very hard to see with array values.
Calling Controller Action:
var jString = JSON.stringify(val);
window.open ('".$this->createUrl('campaign/reportdrill')."/id/'+jString,'_blank');
URL Formed :
http://sks14/viacrm/campaign/reportdrill/id/%5B%7B%22Campaign%22:193,%22Filter%22:651,%22crm_post_code_categ_id%22:%221%22,%22crm_campaign_post_code_id%22:%22296%22,%22todate%22:%2214-05-2014%22,%22fromdate%22:%2201-05-2014%22,%22agent%22:%22%22%7D%5D
How to hide this parameter from user or is anyother way to pass array of values to controller action ?
This is the only way to pass parameters via the GET method of URLs. If you want to 'hide' the URL, use an AJAX load instead.
var jString = JSON.stringify(val);
$('body').load('".$this->createUrl('campaign/reportdrill')."/id/'+jString);
However, AJAX load cannot apply to opening a new window. You will still need to use your URL for that purpose.
I'm writing a simple API, and building a simple web application on top of this API.
Because I want to "consume my own API" directly, I first Googled and found this answer on StackOverflow which answers my initial question perfectly: Consuming my own Laravel API
Now, this works great, I'm able to access my API by doing something like:
$request = Request::create('/api/cars/'.$id, 'GET');
$instance = json_decode(Route::dispatch($request)->getContent());
This is great! But, my API also allows you to add an optional fields parameter to the GET query string to specify specific attributes that should be returned, such as this:
http://cars.com/api/cars/1?fields=id,color
Now the way I actually handle this in the API is something along the lines of this:
public function show(Car $car)
{
if(Input::has('fields'))
{
//Here I do some logic and basically return only fields requested
....
...
}
I would assume that I could do something similar as I did with the query string parameter-less approach before, something like this:
$request = Request::create('/api/cars/' . $id . '?fields=id,color', 'GET');
$instance = json_decode(Route::dispatch($request)->getContent());
BUT, it doesn't seem so. Long story short, after stepping through the code it seems that the Request object is correctly created (and it correctly pulls out the fields parameter and assigns id,color to it), and the Route seems to be dispatched OK, but within my API controller itself I do not know how to access the field parameter. Using Input::get('fields') (which is what I use for "normal" requests) returns nothing, and I'm fairly certain that's because the static Input is referencing or scoping to the initial request the came in, NOT the new request I dispatched "manually" from within the app itself.
So, my question is really how should I be doing this? Am I doing something wrong? Ideally I'd like to avoid doing anything ugly or special in my API controller, I'd like to be able to use Input::get for the internally dispatched requests and not have to make a second check , etc.
You are correct in that using Input is actually referencing the current request and not your newly created request. Your input will be available on the request instance itself that you instantiate with Request::create().
If you were using (as you should be) Illuminate\Http\Request to instantiate your request then you can use $request->input('key') or $request->query('key') to get parameters from the query string.
Now, the problem here is that you might not have your Illuminate\Http\Request instance available to you in the route. A solution here (so that you can continue using the Input facade) is to physically replace the input on the current request, then switch it back.
// Store the original input of the request and then replace the input with your request instances input.
$originalInput = Request::input();
Request::replace($request->input());
// Dispatch your request instance with the router.
$response = Route::dispatch($request);
// Replace the input again with the original request input.
Request::replace($originalInput);
This should work (in theory) and you should still be able to use your original request input before and after your internal API request is made.
I was also just facing this issue and thanks to Jason's great answers I was able to make it work.
Just wanted to add that I found out that the Route also needs to be replaced. Otherwise Route::currentRouteName() will return the dispatched route later in the script.
More details to this can be found on my blog post.
I also did some tests for the stacking issue and called internal API methods repeatedly from within each other with this approach. It worked out just fine! All requests and routes have been set correctly.
If you want to invoke an internal API and pass parameters via an array (instead of query string), you can do like this:
$request = Request::create("/api/cars", "GET", array(
"id" => $id,
"fields" => array("id","color")
));
$originalInput = Request::input();//backup original input
Request::replace($request->input());
$car = json_decode(Route::dispatch($request)->getContent());//invoke API
Request::replace($originalInput);//restore orginal input
Ref: Laravel : calling your own API
I'd like to make a menu in Layout which the items are linked to other different module.
e.g:
Item "Product" linked to an action in Product Module, item "Service" linked to an action in Service Module.
It won't work when I set the 'url'=>('product/<controllerID>/<actionID>') and 'url'=>('service/<controllerID>/<actionID>') because once we're in Product module and click the menu "Service", the URL become
index.php?r=product/service/<controllerID>/<actionID>
instead of
index.php?r=service/<controllerID>/<actionID>
and it will be 404 error. (for sure, because the Service Module isn't inside Product Module but the URL makes it looks like that).
Any solution for this?
Check the createUrl() documentation :
the URL route. This should be in the format of 'ControllerID/ActionID'. If the ControllerID is not present, the current controller ID will be prefixed to the route. If the route is empty, it is assumed to be the current action. If the controller belongs to a module, the module ID will be prefixed to the route. (If you do not want the module ID prefix, the route should start with a slash '/'.)
That last line tells us everything. Best thing to do for you is start all the routes with a / :
'url'=>array('/<moduleID>/<controllerID>/<actionID>')
Check this
'url'=>$this->createUrl('/<moduleId>/<controllerID>/<actionID>')