Symfony 3.0问题,重定向到另一个路由

时间:2016-02-23 21:10:10

标签: symfony routing

我在Symfony 3.0上制作了以下控制器

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

/*Request Response*/
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
/*End of: "Request Response"*/

use Gregwar\Captcha\CaptchaBuilder;
use Symfony\Component\HttpFoundation\Session\Session;

class PagesController extends Controller
{

 /**
  *@Route("/", name="index")
  */
  public function index(Request $request2)
  {
    $session=  $request2->getSession();
    $response = $this->render("pages/index.html.twig");
    return $response;
  }


  /**
  *@Route("/panel",name="panel"')
  */
  public function panel(Request $request2)
  {
    $session=  $request2->getSession();
    if(!$session->has('user_id'))  return $this->redirectToRoute('index');

    return Response("Hello");
  }

}

但是当我在浏览器上访问http://127.0.0.1:8000/panel时,会显示以下消息:

[Syntax Error] Expected Doctrine\Common\Annotations\DocLexer::T_CLOSE_PARENTHESIS, got ''' at position 28 in method AppBundle\Controller\PagesController::panel() in /home/pcmagas/Kwdikas/php/apps/symphotest/src/AppBundle/Controller/ (which is being imported from "/home/pcmagas/Kwdikas/php/apps/symphotest/app/config/routing.yml"). 

我不知道为什么会这样。

1 个答案:

答案 0 :(得分:4)

只是一个错字,看看你的路线注释:

*@Route("/panel",name="panel"')

你最后看到'了吗?应该是:

*@Route("/panel",name="panel")