Borys Pawluczuk

Borys Pawluczuk programista
web/mvc/rest

Temat: Symfony cmf - tłumaczone dokumenty

Znalazłem w sieci przykład dokumentu zawierającego pole image, które może zmieniać się w zależności od wersji językowej. Jednak nie mam pojęcia jak tego używać tzn jak wyświetlać takie pole? Czy jest możliwy upload do tego pola po stronie sonata admin? Czy ma ktoś gotowy kod który może mi tu wkleić jak z tego korzystać w praktyce? W przykładzie jest tylko pokazane jak importować taki dokument programowo ale już o wyświetlaniu nic nie mogę znaleźć.


use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;

/**
* @PHPCRODM\Document(alias="translation_article", translator="attribute")
*/
class Article
{
/** @PHPCRODM\Id */
public $id;

/**
* The language this document currently is in
* @PHPCRODM\Locale
*/
public $locale = 'en';

/**
* Untranslated property
* @PHPCRODM\Date
*/
public $publishDate;

/**
* Translated property
* @PHPCRODM\String(translated=true)
*/
public $topic;

/**
* Language specific image
* @PHPCRODM\Binary(translated=true)
*/
public $image;
}


$localePrefs = array(
'en' => array('en', 'fr'),
'fr' => array('fr', 'en'),
);

$dm = new \Doctrine\ODM\PHPCR\DocumentManager($session, $config);
$dm->setLocaleChooserStrategy(new LocaleChooser($localePrefs, 'en'));

// then to use translations:

$doc = new Article();
$doc->id = '/my_test_node';
$doc->publishedDate = new \DateTime();
$doc->topic = 'An interesting subject';
$doc->image = fopen('english.jpg');

// Persist the document in English
$this->dm->persistTranslation($this->doc, 'en');

// Change the content and persist the document in French
$this->doc->topic = 'Un sujet intéressant';
$doc->image = fopen('english.jpg');
$this->dm->persistTranslation($this->doc, 'fr');

// Flush to write the changes to the phpcr backend
$this->dm->flush();

// Get the document in default language (English if you bootstrapped as in the example)
$doc = $this->dm->find('Doctrine\Tests\Models\Translation\Article', '/my_test_node');
echo $doc->topic;

// Get the document in French (updates the existing document)
$this->dm->find('Doctrine\Tests\Models\Translation\Article', '/my_test_node', 'fr');
echo $doc->topic;