Cakephp 屈折变化,如何将复数变为单数?

发布于 2024-09-04 02:21:31 字数 73 浏览 5 评论 0原文

我有一个名为“商店”的控制器,这是路由系统查​​找它的方式,但是我希望能够调用该控制器而不是“商店”。

可以这样做吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贩梦商人 2024-09-11 02:21:31

听起来您只是想将 URL 从 example.com/shops 更改为 example.com/shop ...这是正确的吗?如果是这样,请编辑 app/config/routes.php 以包含以下行:

路由器::connect('/shop/*',
array('controller' => 'shops'));


注意:上面的解决方案可能就是您正在寻找的,但是如果您打算让 CakePHP 永远不会将“shop”复数为“shops”,那么您可以按照以下方式执行此操作:

您可以编辑 app/config/inflections.php 并修改 $uninflectedPlural 数组以包含“shop”。

例如:

$uninflectedPlural = array('商店');

从那时起,您的控制器将是: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:

Router::connect('/shop/*',
array('controller' => 'shops'));


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:

$uninflectedPlural = array('shop');

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"

隔纱相望 2024-09-11 02:21:31

是的。转到 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文