【问题标题】:CakePHP: routes and static pagesCakePHP:路由和静态页面
【发布时间】:2011-10-24 19:54:08
【问题描述】:

我正在做一个小项目——网站。有画廊、用户登录、商店和许多小的文本部分——有图像和没有图像。 例如,我想制作漂亮的网址:

Gallery -> /eng/gallery (GalleryController::index)
Gallery album /eng/gallery/album_name_slug (GalleryController::view)
Shop -> /eng/products (ProductsController::index)
Shop one product -> /eng/products/product_name_slug (ProductsController::view)

所有其他(文本)页面都转到“PagesController”,但没有 /pages/view 前缀

Contacts -> /eng/contacts
About us -> /eng/about_us

我认为我可以制作这样的东西:

// Homepage
Router::connect('/', array('controller' => 'homepage', 'action' => 'display'));

/* There delegate routes for each controller/method (gallery, shop, etc) */

// All what is not in thease controllers/methods goes to pagescontroller
Router::connect('/*', array('controller' => 'pages', 'action' => 'view'));

在 routes.php 中制作它的最佳方法是什么?也许你可以举一些通用的例子?

谢谢!

【问题讨论】:

  • 我认为您的路线没有任何问题。什么不工作?
  • 我想知道是否有可能,让这个工作,而不是委托所有功能(产品/画廊)路线,只有全部?
  • “委托所有功能路由”是什么意思?
  • 嗯...我的问题很糟糕。无论如何,谢谢!

标签: cakephp routing


【解决方案1】:

对于图库 -> /eng/gallery (GalleryController::index) :

Router::connect('/eng/gallery', 
    array('controller' => 'gallery', 'action' => 'index'));

对于图库相册/eng/gallery/album_name_slug(GalleryController::view):

Router::connect('/eng/gallery/:album', 
    array('controller' => 'gallery', 'action' => 'view'), 
    array('pass' => array('album'),'album' => '[0-9a-zA-Z]+') 
); 

重复产品控制器

【讨论】:

  • 不可能使用控制器和方法作为默认值,并且只有在没有这样的控制器/方法进入页面控制器的情况下?我正在寻找 DRY 解决方案。当然如果没有,我会接受你的回答!
  • 我的全部内容包括:Router::connect('/*', array('controller' => 'pages', 'action' => 'display'));
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-28
  • 2019-06-05
  • 1970-01-01
  • 2012-07-01
  • 1970-01-01
相关资源
最近更新 更多