我创建了一个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>');
}
}
路由文件如下所示。
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;
显示以下错误
页面未正确重定向
我想要做的是一旦使用索引操作调用默认控制器,它将使用一个参数重定向到myaction Action。
所以请任何帮助...
答案 0 :(得分:5)
您的应用会以永远无法完成的方式重定向请求。所以你有一些重定向循环。
您的代码似乎没问题。但是,您不应该在路由文件中硬编码参数,而是像这样
$this->redirect($this->generateUrl('home', array('name' => 'test')));
您有更多路由定义吗?也许他们互相干涉。你可以张贴你的日志吗?