English 中文(简体)
传统陶器种类
原标题:Custom url generator class
  • 时间:2012-01-13 15:34:13
  •  标签:
  • symfony

I am looking for a way to override the generation of the url for a specific route in Symfony2. In symfony 1.4 I used to do it like this:

RouteName:
  class: sfDoctrineRouteCollection
  options:
    model:                Model
    prefix_path:          /route/:id/:slug
    column:               id
    route_class:          CustomDoctrineRoute

class CustomDoctrineRoute extends sfDoctrineRoute
{
  public function generate($params, $context = array(), $absolute = false)
  {
    //custom logic on route params

    return parent::generate($params, $context, $absolute);
  }

}
最佳回答

你们能够战胜核心 路线:

<parameters>
    <parameter key="router.class">CompanyBundleRouterCustomRouter</parameter>
</parameters>

Default Liner(SymfonyBundleFrameworkBundleRoutingRouter)有缺省选择(见确定方法),你可以将其置于贵方的参数中,超出所需的类别,而是所有航道者:

router.options.generator_class:  CompanyBundleRouterUrlGenerator

I hope this will solve your problem.

问题回答

暂无回答




相关问题
Symfony 5, I can t start the server

I develop a symfony project and everything was fine. But since yesterday I can not launch the server: enter image description here The commands symfony server:start and symfony server:stop don t work ...

learning symfony 1.4 will be good when using symfony 2.0?

I know that the architecture is different in symfony 2.0 but im learning 1.4 right now. I wonder if this knowledge i gain about 1.4 will be usable for 2.0 in some extent or will it be a total waste ...

Is symfony 2.0 stable enough to use? [closed]

I wonder if Symfony 2.0 is stable enough to use? Because I ve never used Symfony before. It seems that Symfony 2 is much better than the previous version and I don t want to relearn/recode ...

your experience using symfony 2.0 [closed]

I m going to start a new project that s building web apps from scratch. I have been thinking about using symfony framework for this project. Should I start using symfony 2.0 or stick with 1.4 ? I ...

How to increase the session timeout in Symfony

I would like to know how to increase the session timeout in symfony. Is it enough to only adjust the symfony configuration settings or must I also configure anything in my php.ini file?

How stable or unstable is symfony 2.0? [closed]

Well, I know it s a preview, and I know it says that it s not yet ready for production, and yet I dare ask the question. I need to start building a pretty big application, which is planned to go live ...

热门标签