简体   繁体   English

我的symfony2控制器未重定向

[英]My symfony2 controller is not redirecting

I have created one defaultcontroller which is given below 我创建了一个defaultcontroller,如下所示

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>');
}

} }

The routing file is as look like bellow. 路由文件如下所示。

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;

It shows the following error 它显示以下错误

The page isn't redirecting properly 页面未正确重定向

What i want to do is once the default controller is called with index action it will redirect to myaction Action with one argument. 我想做的是,一旦使用索引操作调用了默认控制器,它将使用一个参数重定向到myaction Action。

so please any help... 所以请帮忙...

Your app redirects the request in a way that will never complete. 您的应用将以永远无法完成的方式重定向请求。 So you have some kind of redirection loop. 因此,您有某种重定向循环。

It seems that your code is OK. 看来您的代码还可以。 However your should not hardcode parameters in the routing file but like this 但是,您不应该在路由文件中对参数进行硬编码,而是像这样

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

Do you have more routing definitions? 您还有更多的路由定义吗? Maybe they interfere each other. 也许他们互相干扰。 Can you post your log? 您可以发布日志吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM