Symfony-3.2"无法访问私有财产......"

时间:2017-05-20 17:49:56

标签: php symfony-3.2

我有问题。我尝试从DB获取值并将其添加到数组中。然后我想通过Twig {{content.language.text_logo}}在模板中使用此数组进行渲染。 如何将数组中对象的属性更改为" public"?

这是我的IndexController.php

<?php
namespace Seandle\HomeBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

class IndexController extends Controller {
  public function indexAction() {
    return $this->render('SeandleHomeBundle:Default:index.html.twig', array(
      'content' => $this->getLanguage(),
    ));
  }

  private function getLanguage() {
    $repository = $this->getDoctrine()->getRepository('SeandleHomeBundle:SeandleLanguage');
    $languages = $repository->findAll();
    $language = array();
    foreach ($languages as $language_key => $language_value) {
      $language['language'] = array(
        $language_value->languageLocation => array(
          $language_value->languageVariable => $language_value->languageContent
        )
      );
    }
    return $language;
  }
}

This is screenshot from browser

1 个答案:

答案 0 :(得分:1)

如果财产是私人财产,通常会与吸气人相处。

$language_value->getLanguageLocation();

我建议您将此功能移至服务器,控制器中的蚂蚁呼叫服务。更多:

http://symfony.com/doc/current/service_container.html