[英]How to reverse route to an action from my form in Play Framework 2.3
今天是個好日子,
我是Play框架的新手,正在嘗試開始構建應用程序。 在app/controllers
文件夾下,我創建了子包,因此我有一些類似於app/controllers/products/ProductController.class
。
在我的routes.conf
文件中,我添加了這樣的示例路由
GET /createproduct controllers.products.ProductController.listAllProducts() POST /createproduct controllers.products.ProductController.createProductDetail()
我可以轉到URL http://localhost:9000/createproduct
並查看我創建的示例視圖。
我現在的問題是我想向視圖中添加表單,並且當我嘗試使用表單助手方法將數據從我的新視圖中發布到上述POST URL時,如下所示
@helper.form(action = routes.products.ProductController.createProductDetail()) {
我得到的錯誤
value products is not a member of object controllers.routes
我在網上看到的所有示例僅使用route.Application示例,這不適合我的問題。
所以我的問題是我該如何反向路由到該操作或使用表單幫助程序從視圖反向路由
有效語法為:
[full-package-name].routes.[controller].[method]
所以你的情況應該是
controllers.products.routes.ProductController.createProductDetail()
controllers.routes
是隱式導入的,因此要與默認包中的控制器一起使用,可以將其縮寫為:
routes.Controller.action()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.