我对框架symfony有些麻烦。我使用KernelRequest管理我的路由。 在控制器中,我有正确的路线名称和正确的参数;但是在另一个控制器(完全相同,只是页面改变)中,路由生成了诸如http,https,scheme等的参数(见下文)。
Candidate.php
<?php
namespace AppBundle\Controller;
use AppBundle\AppBundle;
use AppBundle\Entity\CandidateAction;
use AppBundle\Entity\CandidateNotice;
use AppBundle\Entity\CandidateSchool;
use AppBundle\Entity\CandidateSkill;
use AppBundle\Entity\Document;
use AppBundle\Entity\ListElement;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Doctrine\ORM\Query;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use AppBundle\Entity\Candidate;
use AppBundle\Form\CandidateType;
use AppBundle\Utils\EnumRight;
use AppBundle\Utils\EventCalendar;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use MBence\OpenTBSBundle\OpenTBSBundle;
/**
* Candidat controller.
*
* @Route("/candidate")
*/
class CandidateController extends Controller
{
/**
* Lists all Candidat entities.
*
* @Route("/", name="candidate_index")
* @Method("GET")
*/
public function indexAction(Request $request)
{
$session = $request->getSession();
$session->set('tabActive', 'personalData');
$userHistory = $session->get("userContext")->getUserHistory();
$user = $this->get('security.token_storage')->getToken()->getUser();
if ($session->get("userContext")->hasPermission($user, EnumRight::candidate, EnumRight::candidate_show_list)) {
return $this->render('AppBundle:candidate:index.html.twig', array());
} else {
$this->get("session")->getFlashBag()->add('danger', $this->get('translator')->trans('rights.forbidden'));
$userHistory->popFromHistory();
return $this->redirect($this->generateUrl($userHistory->getPreviousRoute()['name'], $userHistory->getPreviousRoute()['params']));
}
}
}
tender.php
<?php
namespace AppBundle\Controller;
use AppBundle\AppBundle;
use AppBundle\Entity\Document;
use AppBundle\Entity\ListElement;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Doctrine\ORM\Query;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use AppBundle\Entity\Tender;
use AppBundle\Form\TenderType;
use AppBundle\Utils\EnumRight;
use AppBundle\Utils\EventCalendar;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use MBence\OpenTBSBundle\OpenTBSBundle;
/**
* Tender controller.
*
* @Route("/tender")
*/
class TenderController extends Controller
{
/**
* Lists all Tender entities.
*
* @Route("/", name="tender_index")
* @Method("GET")
*/
public function indexAction(Request $request)
{
$session = $request->getSession();
$session->set('tabActive', 'personalData');
$userHistory = $session->get("userContext")->getUserHistory();
$user = $this->get('security.token_storage')->getToken()->getUser();
if ($session->get("userContext")->hasPermission($user, EnumRight::tender, EnumRight::tender_show_list)) {
return $this->render('AppBundle:tender:index.html.twig', array());
} else {
$this->get("session")->getFlashBag()->add('danger', $this->get('translator')->trans('rights.forbidden'));
$userHistory->popFromHistory();
return $this->redirect($this->generateUrl($userHistory->getPreviousRoute()['name'], $userHistory->getPreviousRoute()['params']));
}
}
}
如您所见,它在两个不同的控制器中具有完全相同的功能。
第一个路线:(在我的html视图中使用转储)
"name" => "candidate_index"
"params" => []
第二条路线:
"name" => "tender_index"
"params" => array:5 [▼
"path" => "/tender/"
"permanent" => true
"scheme" => null
"httpPort" => 80
"httpsPort" => 443
]
以下是此命令的结果:php / bin console debug:招标和候选人的路由器:
$ php bin/console debug:router tender_index
+--------------+---------------------------------------------------------+
| Property | Value |
+--------------+---------------------------------------------------------+
| Route Name | tender_index |
| Path | /tender/ |
| Path Regex | #^/tender/$#s |
| Host | ANY |
| Host Regex | |
| Scheme | ANY |
| Method | GET |
| Requirements | NO CUSTOM |
| Class | Symfony\Component\Routing\Route |
| Defaults | _controller: AppBundle:Tender:index |
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
+--------------+---------------------------------------------------------+
$ php bin/console debug:router candidate_index
+--------------+---------------------------------------------------------+
| Property | Value |
+--------------+---------------------------------------------------------+
| Route Name | candidate_index |
| Path | /candidate/ |
| Path Regex | #^/candidate/$#s |
| Host | ANY |
| Host Regex | |
| Scheme | ANY |
| Method | GET |
| Requirements | NO CUSTOM |
| Class | Symfony\Component\Routing\Route |
| Defaults | _controller: AppBundle:Candidate:index |
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
+--------------+---------------------------------------------------------+
非常感谢您的协助。
编辑: 我发现了日志文件中的差异。 该控制器被称为:
[2016-08-26 10:47:52] request.INFO: Matched route "tender_index". {"route_parameters":{"_controller":"Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction","path":"/tender/","permanent":true,"scheme":null,"httpPort":80,"httpsPort":443,"_route":"tender_index"},"request_uri":"http://capfivm403.capfigroup.domain.com/~mlerouzic/weberp.dev/web/app_dev.php/tender"} []
而不是:
[2016-08-26 10:52:56] request.INFO: Matched route "tender_index". {"route_parameters":{"_controller":"AppBundle\\Controller\\TenderController::indexAction","_route":"tender_index"},"request_uri":"http://capfivm403.capfigroup.domain.com/~mlerouzic/weberp.dev/web/app_dev.php/tender/?httpPort=80&httpsPort=443&path=%2Ftender%2F&permanent=1"} []
答案 0 :(得分:0)
我已经在我的投标控制器中重写了主要路线的名称......它有效...我不知道为什么。在我的控制台中更新作曲家后,可能是框架中的错误。