Vir*_*j.S 0 php symfony symfony-2.1
我创建了一个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>');
}
Run Code Online (Sandbox Code Playgroud)
}
路由文件如下所示.
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',
Run Code Online (Sandbox Code Playgroud)
)));
return $collection;
Run Code Online (Sandbox Code Playgroud)
它显示以下错误
页面未正确重定向
我想要做的是一旦使用索引操作调用默认控制器,它将使用一个参数重定向到myaction Action.
所以请任何帮助......
您的应用会以永远无法完成的方式重定向请求.所以你有一些重定向循环.
看来你的代码还可以.但是,您不应该在路由文件中硬编码参数,但是这样
$this->redirect($this->generateUrl('home', array('name' => 'test')));
Run Code Online (Sandbox Code Playgroud)
你有更多的路由定义吗?也许他们互相干涉.你可以发布你的日志吗?