1

我在 symfony 1.4 中有一个现有项目

对于静态页面,我们使用提供以下 URL 的模块 Page:

http://www.example.com/page/aboutus
http://www.example.com/page/faq
http://www.example.com/ (page/index method, points to method page/home)

对于新的需求,我们需要以下格式的 URL:

http://www.example.com/aboutus
http://www.example.com/faq
http://www.example.com/  (index/home method of page module; working as page is default module)

有 16 个这样的静态页面,都列在page模块下。到目前为止,我正计划创建 16 个新模块,并将每个静态页面放在index新模块的方法中,但我想这是一个糟糕的解决方案,希望 symfony 绝对不是为了以这种方式使用而设计的。

有没有办法从 URL 中跳过模块名称,至少对于默认模块?

4

2 回答 2

2

您可能想要使用 http://corz.org/serv/tricks/htaccess2.php中解释的重写规则

于 2012-10-19T05:19:52.563 回答
1

使用 symfony 的路由功能!

routing.yml

aboutus_page:
  url:   /aboutus
  param: { module: page, action: aboutus }

faq_page:
  url:   /faq
  params: { module: page, action: faq }

home_page:
  url:   /
  params: { module: page, action: index }

# your other routes
# ...

actions.class.php您的模块page将如下所示:

class pageActions extends sfActions
{
   public function executeAboutus (sfWebRequest $request)
   {
      // ...
   }

   public function executeFaq (sfWebRequest $request)
   {
      // ...
   }
于 2012-10-19T14:19:28.500 回答