2012-12-26 90 views
0

我有四个child_routes调用相同的控制器和操作。路线中的标准参数

 

    'noticia' => array(
     'type' => 'Segment', 
     'options' => array(
      'route' => 'noticia[/:slug]', 
      'constraints' => array(
        'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
        'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
      ), 
      'defaults' => array(
       '__NAMESPACE__' => 'Application\Controller', 
       'controller' => 'Post', 
       'action'  => 'index', 
      ), 
     ), 
    ), 
    'dica' => array(
     'type' => 'Segment', 
     'options' => array(
      'route' => 'dica[/:slug]', 
      'constraints' => array(
       'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
       'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
      ), 
      'defaults' => array(
       '__NAMESPACE__' => 'Application\Controller', 
       'controller' => 'Post', 
       'action'  => 'index', 
      ), 
     ), 
    ), 
    'ovarejao' => array(
     'type' => 'Segment', 
     'options' => array(
      'route' => 'o-varejao[/:slug]', 
      'constraints' => array(
       'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
       'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
      ), 
      'defaults' => array(
       '__NAMESPACE__' => 'Application\Controller', 
       'controller' => 'Post', 
       'action'  => 'index', 
      ), 
     ), 
    ), 
    'servicos' => array(
     'type' => 'Segment', 
     'options' => array(
      'route' => 'servicos[/:slug]', 
      'constraints' => array(
       'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
       'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
      ), 
      'defaults' => array(
       '__NAMESPACE__' => 'Application\Controller', 
       'controller' => 'Post', 
       'action'  => 'index', 
      ), 
     ), 
    ), 

我需要的是传递一个参数,以便我可以区分这些路线。怎么做?

回答

1

我认为你的结构有点不合适。为何一个控制器的一个动作有四条不同的路线?这几乎没有意义。

相反的路线每次所设置的路线至今servicosovarejaodicanoticia与像servicosActionovarejaoActiondicaActionnoticiaAction

类似行动PostController中如果操作是非常相似的相应的视图,你也可以使用一个模板来执行所有的操作,这将使模板更容易一些。这是这样做的:

public function servicosAction() 
{ 
    $vm = new ViewModel(); 
    $vm->setTemplate('namespace/post/multiple.phtml'); 

    // Grab data from your model here with some parameter 

    return $vm->setVariables(array(
     //key-value paired array of view variables 
    )); 
} 

如果这不符合您的标准,请让您的问题更清楚。究竟是什么,你想实现?