[英]How to reverse route to an action from my form in Play Framework 2.3
Good day Everyone, 今天是个好日子,
I am new to Play framework and am trying to get started building an application. 我是Play框架的新手,正在尝试开始构建应用程序。 Under the app/controllers
folders i have created sub packages so i have something like app/controllers/products/ProductController.class
. 在app/controllers
文件夹下,我创建了子包,因此我有一些类似于app/controllers/products/ProductController.class
。
In my routes.conf
file i have added a sample route like this 在我的routes.conf
文件中,我添加了这样的示例路由
GET /createproduct controllers.products.ProductController.listAllProducts() POST /createproduct controllers.products.ProductController.createProductDetail()
and i can goto the url http://localhost:9000/createproduct
and see a sample view that i created. 我可以转到URL http://localhost:9000/createproduct
并查看我创建的示例视图。
My issue now is that i want to add a form to the view and when i try to use the form helper method to POST data to the POST URL above from my new view like this 我现在的问题是我想向视图中添加表单,并且当我尝试使用表单助手方法将数据从我的新视图中发布到上述POST URL时,如下所示
@helper.form(action = routes.products.ProductController.createProductDetail()) {
i get the error that 我得到的错误
value products is not a member of object controllers.routes
All the samples that i saw online only use the route.Application example which is doesnt fit my issue. 我在网上看到的所有示例仅使用route.Application示例,这不适合我的问题。
So my question is how do i reverse route to this action or route from a view using the Form helper 所以我的问题是我该如何反向路由到该操作或使用表单帮助程序从视图反向路由
The valid syntax is: 有效语法为:
[full-package-name].routes.[controller].[method]
So in your case it should be 所以你的情况应该是
controllers.products.routes.ProductController.createProductDetail()
controllers.routes
is imported implicity, therefore for using with controllers in default package you can short it to: controllers.routes
是隐式导入的,因此要与默认包中的控制器一起使用,可以将其缩写为:
routes.Controller.action()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.