Symfony2.7 컨트롤러에서 Twig로 변수 전달
컨트롤러의
$this->render 제 2 인수에 배열로 건네주면 Twig 측에서 픽업합니다.before
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class ConcertController extends Controller
{
    /**
     * @Route("/page/")
     **/
    public function indexAction()
    {
        return $this->render('Page/index.html.twig');
    }
}
after
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class ConcertController extends Controller
{
    /**
     * @Route("/page/")
     **/
    public function indexAction()
    {
        $information = "add new concert";
        $args = [
            'informations' => [
                '201610' => 'Add new page',
                '201611' => 'Add news page',
                '201612' => 'Delete old page',
            ],
            'title' => 'Example Site'
        ];
        return $this->render(
            'Page/index.html.twig',
            $args
        );
    }
}
Twig에서 데리러
전달한 값은 두 번째 인수의 키 이름으로 선택됩니다.
<html>
<body>
    <h1>{{ title }}</h1>
    <ul>
        {% for key, item in informations %}
            <li>{{ key }}: {{ item }}</li>
        {% endfor %}
    </ul>
</body>
</html>
출력
                Reference
이 문제에 관하여(Symfony2.7 컨트롤러에서 Twig로 변수 전달), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/motchi0214/items/dbd98a315e5841894ee5텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)