0

我想在我的控制器中路由回索引('/')。我该怎么做,我尝试了以下方法:

public function randomAction()
{
  return $this->redirect()->toRoute('/');
}

但是有了这个我得到以下错误:

找不到名称为“”的路线

任何想法为什么会发生这种情况,以及如何正确路由回索引?我可以使用/application,但我不希望它出现在地址栏中。在这种情况下我是唯一的选择toUrl('/')吗?

4

2 回答 2

1

You need to pass the name of the route to toRoute, not the actual route.

If you are using the ZF Skeleton Application then the "index" route is called home so you'd do the following:

return $this->redirect()->toRoute('home');

If not open your module config and find the routes array. The name of the route is the key in this array that points to your route configuration.

于 2013-10-20T13:44:44.570 回答
1

例如在骨架应用程序上,尝试回家的路线。

public function randomAction()
{
  return $this->redirect()->toRoute('home');
}

ZF2 文档

toRoute($route, array $params = array(), array $options = array()):重定向到命名路由,使用提供的 $params 和 $options 组装 URL。

于 2013-10-20T13:43:53.347 回答