2016-08-25 2 views
1

У меня есть проблемы с каркасом symfony. Я использую KernelRequest для управления своими маршрутами. В контроллере у меня есть правильное имя маршрута и правильные параметры; но в другом контроллере (который точно совпадает с изменением страницы) маршрут генерирует параметры, такие как http, https, схема и т. д. (см. ниже).Проблемы с маршрутизацией Symfony3 (KernelRequest)

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 | 
+--------------+---------------------------------------------------------+ 

Ваша помощь будет принята с благодарностью.

EDIT: Я нашел разницу в файле журнала. Этот контроллер называется:

[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

проверьте свои маршруты [с помощью команд консоли] (http://symfony.com/doc/current/routing/debug.html) вместо их сброса, все дополнительные параметры, которые вы дамп, вероятно, не имеют значения в представлении , – NDM

+0

Вы можете увидеть результат этой команды в моем сообщении (я ее отредактировал). Я до сих пор не понимаю разницы и откуда пришли тезисы параметров. Спасибо за вашу помощь. –

ответ

0

Я переписал имя главного маршрута в моем нежном контроллер и ... это работает ... Я не очень знаю, почему. Возможно, ошибка в каркасе после обновления композитора в моей консоли.