누군가이 주제에 대해 저를 도울 수 있기를 바랍니다.Symfony2 : 부모 렌더링의 변수 값을 변경하려면 어떻게해야합니까?
Symfony 2 구조에 두 개의 컨트롤러가 있는데, 두 번째 컨트롤러는 첫 번째 컨트롤러보다 우선합니다.
다음부모 컨트롤러의 코드 :
<?php
namespace WebSender\MainPageBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function indexAction()
{
$Header_Title = "Titolo 1";
$content_area = "Contenuto di prova 1!";
$Header_Welcome = "Benvenuto utente: ";
$username = "nome utente";
$Header_Logout = "Logout";
return $this->render('WebSenderMainPageBundle:Default:index.html.php', array('Header_Title' => $Header_Title, 'content_area' => $content_area, 'Header_Welcome' => $Header_Welcome, 'username' => $username, 'Header_Logout' => $Header_Logout));
}
}
그리고 두 번째 컨트롤러 : 당신이 볼 수 있듯이
<?php
namespace WebSender\MainPageBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use WebSender\MainPageBundle\Controller\DefaultController as BaseController;
class GridController extends BaseController
{
public function indexAction()
{
$Header_Title = "Titolo 2";
$content_area = "Contenuto di prova 2!";
$response = parent::indexAction();
// return $this->render('WebSenderMainPageBundle:Default:index.html.php', array('Header_Title' => $Header_Title, 'content_area' => $content_area, 'Header_Welcome' => $Header_Welcome, 'username' => $username, 'Header_Logout' => $Header_Logout));
return $response;
}
}
, 나는 "특히, $ 응답 값을 변경하는 방법을 모른다 content_area "및"Header_Title ".
감사합니다.
Symfony에서는 컨트롤러를 새로운 것으로 오버라이드 할 수 있습니다. 즉, 컨트롤러의 전체 또는 일부를 다른 컨트롤러로 "확장"할 수 있습니다. –