I am trying to know how to add query parameters to routes in Lumen
this is an example of a route I created
$app->get('/product/{apikey}','ProductController#getProduct');
This works when I use
http://api.lumenbased.com/product/10920918
but I would like to use it like this
http://api.lumenbased.com/product/?apikey=10920918
I tried this
$app->get('/product/?apikey={apikey}','ProductController#getProduct');
But this gives me MethodNotAllowedHttpException
I would like to know how to write routes with query parameters in Lumen ?
Just do:
$app->get('/product','ProductController#getProduct');
and use:
$request->get('apikey')
in the ProductController#getProduct function.
(That said, validating an API key is better done via middleware...)
Related
In CakePHP 3 the rest routing doesn't call classes in subnamespace. For example the route "posts/2/comments/10" call App\Controller\CommentsController. I want it to call App\Controller\Posts\CommentsController because comments are not always for posts...
Here is my solution :
$routes->resources('Posts');
Router::scope('/posts/:post_id/',['post_id'=>'[0-9]+','prefix'=>'posts'], function($routes){
$routes->resources('Comments');
});
It works fine but i don't know if it is a good practice.
Thank you
If you want to group controllers by namespace use Router::prefix() or $routes->prefix() instead of $routes->scope()
If I construct a Play redirect like Redirect(routes.RegistrationController.register()), how can I add a query parameter to the URL I'm redirecting to?
For example, I'd like a URL like this: /register?token=1234.
You can just do Redirect(routes.RegistrationController.register().url + "?token=1234").
Or, supposing your route declares token as an optional parameter with the route declaration GET /register #controllers.RegistrationController(token: Option[Int]), then you could do Redirect(routes.RegistrationController.register(Some(1234))).
There are various variations to how you could set this up. You may want to see the Play router documentation.
I have a problem trying to use Camel-http4 component. What I want to do is to set from my camel route the Matrix Params that the REST service needs to work properly. Is there any way to do that?
Thank you,
Roxana
Using traditional query parameters, the Camel URI looks as follows:
from("direct:start")
.to("http4://oldhost?order=123&detail=short");
Thus, using matrix parameters should work as well:
from("direct:start")
.to("http4://oldhost;order=123;detail=short");
Edit:
Use Exchange.HTTP_URI for dynamically setting the properties or use recipientList such as:
from("direct:start")
.recipientList(simple("http4://oldhost;order=${header.123Header};detail={{value.from.cfg}}"));
I am trying to figure out how to do a redirect within a controller action in Play (2.0) using Scala.
The redirect using
Redirect(routes.Application.index)
works just fine.
What I cannot figure out from the docs, API, or Google is how to add parameters to the call.
I am coming from Grails where this could be done easily as follows:
redirect action: "index", params: ["key": "value"]
.
The only way I have found is to call Redirect using a string url and a query string, which seems awkward.
Basically I would like to make use of Redirect(Call) somehow, but I do not how to create the Call object using reverse routing.
Am I missing something/not getting the concept in Play/Scala?
Thanks in Advance!
Ellou'
A route is just a function, so you can pass arguments as usual:
// Redirect to /hello/Bob
def helloBob = Action {
Redirect(routes.Application.hello("Bob"))
}
This snippet comes from http://www.playframework.org/documentation/2.0/ScalaRouting (at the bottom)
You can also avoid creating another function just for this in your controller. In your route config, you can simply add something like this:
GET /google #controllers.Default.redirect(to = "http://google.com")
I am a beginner and I am creating some forms to be posted into MySQL using Zend, and I am in the process of debugging but I don't really know how to debug anything using Zend. I want to submit the form and see if my custom forms are concatenating the data properly before it goes into MySQL, so I want to catch the post data to see a few things. How can I do this?
The Default route for zend framework application looks like the following
http://www.name.tld/$controller/$action/$param1/$value1/.../$paramX/$valueX
So all $_GET-Parameters simply get contenated onto the url in the above manner /param/value
Let's say you are within IndexController and indexAction() in here you call a form. Now there's possible two things happening:
You do not define a Form-Action, then you will send the form back to IndexController:indexAction()
You define a Form action via $form->setAction('/index/process') in that case you would end up at IndexController:processAction()
The way to access the Params is already defined above. Whereas $this->_getParam() equals $this->getRequest()->getParam() and $this->_getAllParams() equals $this->getRequest->getParams()
The right way yo check data of Zend Stuff is using Zend_Debug as #vascowhite has pointed out. If you want to see the final Query-String (in case you're manually building queries), then you can simply put in the insert variable into Zend_Debug::dump()
you can use $this->_getAllParams();.
For example: var_dump($this->_getAllParams()); die; will output all the parameters ZF received and halt the execution of the script. To be used in your receiving Action.
Also, $this->_getParam("param name"); will get a specific parameter from the request.
The easiest way to check variables in Zend Framework is to use Zend_Debug::dump($variable); so you can do this:-
Zend_Debug::dump($_POST);
Zend framework is built on the top of the PHP . so you can use var_dump($_POST) to check the post variables.
ZF has provided its own functions to get all the post variables.. Zend_Debug::dump($this->getRequest()->getPost())
or specifically for one variable.. you can use Zend_Debug::dump($this->getRequest()->getPost($key))
You can check post data by using zend
$request->isPost()
and for retrieving post data
$request->getPost()
For example
if ($request->isPost()) {
$postData = $request->getPost();
Zend_Debug::dump($postData );
}