I want to know if it is possible to modify the value of the parameter of the request.
But i don't know how to do this.
I try with
$requestContent = $this->getRequest()->request->get('tactill_customerbundle_customertype');
Next I use
$request->request->replace()
But I don't how to use this method in my case.
Thanks
The replace method replaces all of the parameters in the request, so you probably do not want to do that.
I would use the set method instead - So you can do:
$request->request->set('tactill_customerbundle_customertype', $newValue)
You can read more in the Symfony2 documentation (http://api.symfony.com/2.0/) - you are looking for Symfony\Component\HttpFoundation\Request (which is the $request variable), which then returns a Symfony\Component\HttpFoundation\ParameterBag when you call the request() method.
Related
I use grpc cpp, and want to modify the method name in the client, example: path+method, but the ClientInterceptor could not modify method? How can I do
No, you cannot modify the method name by the interceptor. I guess you considered using pre-send initial metadata but it doesn't allow to change the method name. But the intercept allows you to hijack the call, send a new rpc, and return the result from this new rpc as an original result to achieve what you want to do.
Why I need this?
When I want to change the route from /news/{slug} to /news/{id} for example, I need to replace all places where path('news', {'slug': 'my-post'} is called. I want to pass the entity like so path('news', {'post': post}) and then change the route however I like. This will give me the flexibility to easily change the routes. Thanks.
You cannot pass eneity as param. path function takes only string and number arguments, because this function generate url based on routing.
How do you imagine passing object to browser url bar?
/news/"{object": std_what_the_#?}
Of course you can make your own twig function and pass object to make your url.
This way you can check your object has slug property and choose your route and params. Anyway you have to do it myself.
I hope it help but your question is not clear...
I am using redirect to pass the model object from one method to another method in grails. How can I get the values of that model object in another method.
See my code here
redirect(controller:"inquiry", action:"createSSVInvestigation", model: [inquiryInstance:inquiryInstance], params:['inquiry.id':inquiryInstance.id])
So in the action createSSVInvestigation how can I get the values of inquiryInstance object.
redirect(controller:"inquiry", action:"createSSVInvestigation",params:['inquiryId':inquiryInstance.id])
In createSSVInvestigation action,We get the id of inquiryInstance by params.inquiryId.
def createSSVInvestigation(){
def inquiryInstance= InquiryClassname.get(params.inquiryId)
}
You can use params to pass all your objects/variables and access them from your params in createSSVInvestigation action. Also model is not part of redirect parameters here.
redirect(controller:"inquiry", action:"createSSVInvestigation", params: [...])
Use this
flash.chainModel.inquiryInstance
Update:
The original question was to get inquiryInstance which was set in model. In documentation its mentioned that we should use flash memory. So this is a way to access flash variables once you chain controllers.
I need to put a flag in an kernel.event_listener at stage kernel.controller in order to do something in an kernel.response-listener.
I thought about adding a parameter to the $request object, however have not found any method or this:
http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Request.html
What is the best practice to pass some informatino from an kernel.controller-listener to an kernel.response-listener?
Use-case:
We want to set a cookie based on a validation of a specific request attribute (must be in kernel.controller-stage, since based on the result of the validation, the view may behave different).
The cookie can only be set in the kernel.response-listener, since it has the Response-instance.
You can use $request->attributes to pass around information. In your controller listener:
$request->attributes->set('mykey', 'myvalue');
In your response listener:
$myvalue = $request->attributes->get('mykey');
I'm having a problem getting a controller method that returns a JsonResult to accept parameters passed via the JQuery getJSON method.
The code I’m working on works fine when the second parameter ("data") of the getJSON method call is null. But when I attempt to pass in a value there, it seems as if the controller method never even gets called.
In this example case, I just want to use an integer. The getJSON call that works fine looks like this:
$.getJSON(”/News/ListNewsJson/”, null, ListNews_OnReturn);
The controller method is like this:
public JsonResult ListNewsJson(int? id)
{
…
return Json(toReturn);
}
By putting a breakpoint in the ListNewsJson method, I see that this method gets called when the data parameter of getJSON is null, but when I replace it with value, such as, say, 3:
$.getJSON(”/News/ListNewsJson/”, 3, ListNews_OnReturn);
… the controller method/breakpoint is never hit. Any idea what I'm doing wrong?
I should also mention that the controller method works fine if I manually go to the address via my browser ("/News/ListNewsJson/3").
getJSON expects a set of key/value pairs, not a bare value, so you would need to use { id: 3 } to pass an id value. Unfortunately this will get turned into /News/ListNewsJson/?id=3 which is not what you want. I suggest just appending the value onto the Url to construct it in the route form. I'm also assuming that the value actually comes from a variable so I've written it in that form. If it's possible to be null, then you'll need to do something more complicated to formulate the Url so it makes sense.
var id = '3';
$.getJSON(”/News/ListNewsJson/” + id, ListNews_OnReturn);
i know this is an older thread, but why aren't you using the MVC Url.Action() helper? This would make sure your route is correct.
$.getJSON('<%=Url.Action("ListNewsJson", "News") %>/' + id, ListNews_OnReturn);
Of course, if the id value comes from ViewData you could use the 3rd parameter of the Url.Action() helper method to pass in an anonymous type with an id property, and MVC will create the desired URL. Otherwise, concat it in javascript if the value is coming from the javascript function.
HTH