2013-02-16 101 views
0

我已创建了一个defaultcontroller将在下文我的Symfony2控制器不重定向

namespace Mytest\VameBundle\Controller; 

use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\Response; 

class DefaultController extends Controller 
{ 
public function indexAction() 
{ 
    return $this->redirect($this->generateUrl('home')); 
} 

public function myactionAction($name) 
{ 
    return new Response('<html><body>'.$name.'</body></html>'); 
} 

}

路由文件中给出的是看起来像波纹管。

use Symfony\Component\Routing\RouteCollection; 
use Symfony\Component\Routing\Route; 


$collection = new RouteCollection(); 

$collection->add('name', new Route('/vame',array(
    '_controller' => 'MytestVameBundle:Default:index', 
    ))); 

$collection->add('home', new Route('/vame/{name}',array(
    '_controller' => 'MytestVameBundle:Default:myaction', 
    'name' => 'hhhhhhhhhh', 

)));

return $collection; 

它显示了以下错误

的网页没有正确重定向

什么,我想要做的就是一次默认的控制器被调用index动作会重定向到myaction行动有一个论点。

所以请任何帮助......

回答

5

你的应用程序中重新定向的方式,将永远不会完成的请求。所以你有一些重定向循环。

看来你的代码是好的。然而,你不应该在路由文件中硬编码参数,但是像这样

$this->redirect($this->generateUrl('home', array('name' => 'test'))); 

你有更多的路由定义吗?也许他们互相干扰。你可以发布你的日志?

+0

谢谢,我得到了我的答案。我没有将该参数传递给该网址。 – 2013-02-16 06:47:21