Cakephp 屈折变化,如何将复数变为单数?
我有一个名为“商店”的控制器,这是路由系统查找它的方式,但是我希望能够调用该控制器而不是“商店”。
可以这样做吗?
I have a controller called "Shops", this is the way the routing system looks for it, however I want to be able to called this controller and what not 'shop'.
Is it possible to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您只是想将 URL 从 example.com/shops 更改为 example.com/shop ...这是正确的吗?如果是这样,请编辑 app/config/routes.php 以包含以下行:
注意:上面的解决方案可能就是您正在寻找的,但是如果您打算让 CakePHP 永远不会将“shop”复数为“shops”,那么您可以按照以下方式执行此操作:
您可以编辑 app/config/inflections.php 并修改 $uninflectedPlural 数组以包含“shop”。
例如:
从那时起,您的控制器将是:app/controllers/shop_controller.php,带有“class ShopController extends AppController”,
并且您的模型将照常与app/models/shop.php一起保留,带有“class Shop extends AppModel”
It sounds like you are just trying to just change the URL from example.com/shops to example.com/shop ... is this correct? If so edit app/config/routes.php to include the following line:
Note: The above solution is probably what you are looking for, however if you intended to make CakePHP never pluralise 'shop' to 'shops' then the following is how you do that:
You'd edit app/config/inflections.php and modify the $uninflectedPlural array to include 'shop'.
For example:
From then on your controller will be: app/controllers/shop_controller.php with "class ShopController extends AppController"
And your model will stay as per usual with app/models/shop.php with "class Shop extends AppModel"
是的。转到 www.yoursite.com/shop
查看错误消息并按照模板
或
在route.php 中进行操作。将商店重定向到商店
yes. go to www.yoursite.com/shop
look at the error message and follow the template
OR
in route.php. redirect shop to shops