我正在通过这种方式进行重定向。我想我是这样错了,请引导我更好的方式。zf2中的SEO友好URL
<a href="<?php echo $this->serverUrl()."/restaurantlist/view/".$list['id']."/".$list['name']?>">
<img alt="" src="<?php echo $image; ?>">
</a>
我module.config.php的代码
<?php
return array(
'controllers' => array(
'invokables' => array(
'Restaurantlist\Controller\Restaurantlist' => 'Restaurantlist\Controller\RestaurantlistController',
),
),
'router' => array(
'routes' => array(
'Restaurantlist' => array(
'type' => 'segment',
'options' => array(
// Change this to something specific to your module
'route' => '/restaurantlist[/]',
'defaults' => array(
'controller' => 'Restaurantlist\Controller\Restaurantlist',
'action' => 'list',
),
),
'may_terminate' => true,
'child_routes' => array(
'view' => array(
'type' => 'Segment',
'options' => array(
'route' => '[/]view[/:id][/:name][/]',
'constraints' => array(
'name' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Restaurantlist\Controller\Restaurantlist',
'action' => 'view',
),
),
),
),
),
),
),
'view_helpers' => array(
'factories' => array(
'Requesthelper' => function($sm){
$helper = new \Restaurantlist\View\Helper\Requesthelper;
$request = $sm->getServiceLocator()->get('Request');
$helper->setRequest($request);
return $helper;
}
)
),
'view_manager' => array(
'template_path_stack' => array(
'Restaurantlist' => __DIR__ . '/../view',
),
),
);
它重定向这样 http://test.localhost.com/restaurantlist/view/157/Bluestem 和工作完全正常,但我想这 http://test.localhost.com/Bluestem或http://test.localhost.com/157-Bluestem
我尝试了很多,但没有成功。
是的,它几乎是正确的,但它仍然是“餐馆列表”请参阅链接http://test.localhost.com/restaurantlist/157-Bluestem是否可以像这样http://test.localhost .com/157-Bluestem –
@RajatModi看到我的编辑:-) –
Kuiperes是的,你是对的,但我的默认行动是列表行动我不能通过这种方式改变我必须在子路线只写下这个逻辑:( –