Alors le souci continu lorsque je suis dans la vue d'édition.
Je n'arrive pas à avoir les locales pour les models liés via "contain"
Voici le résultat dans ma vue d'édition
array(
'Page' => array(
'id' => '1',
'meta_key' => '',
'meta_desc' => '',
'name' => 'titre fr qui va bien',
'slug' => 'titre-fr-qui-va-bien',
'content' => '',
'created' => '2014-11-21 14:33:53',
'online' => '0',
'user_id' => '2',
'category_id' => '27',
'draft' => '0',
'acl' => '2',
'locale' => 'fra'
),
(int) 0 => array(
'Page __i18n__ name_fra' => 'titre fr qui va bien',
'Page __i18n__ name_eng' => 'title uk'
),
'Section' => array(
(int) 0 => array(
'id' => '1',
'background' => '',
'page_id' => '1',
'sectionorder' => '0',
'draft' => '0',
'Block' => array(
(int) 0 => array(
'id' => '1',
'cols' => '12',
'offset' => '0',
'background' => '',
'content' => '<p>contenu fr</p>
',
'section_id' => '1',
'blockorder' => '1',
'draft' => '0'
)
)
)
)
)
Voici ma fonction edit
public function backoffice_edit($id = null) {
// on vérifie si on est dans un article existant ou s'il s'agit d'un nouvel article
$this->loadModel("Category");
$this->Page->locale = Configure::read("Config.languages");
if (!empty($this->request->data)) {
$this->request->data'Page']'draft'] = 0;
//debug($this->request->data);
//die();
foreach ($this->request->data'Section'] as $k => $v) {
//$this->request->data'Section'][0]'Block']$k]"draft"] = 0;
$this->request->data'Section']$k]"draft"] = 0;
foreach ($v as $r => $s) {
//debug($s);
if (is_array($s)) {
foreach ($s as $m => $n) {
$this->request->data'Section']$k]'Block']$m]"draft"] = 0;
}
}
}
}
//debug($this->request->data);
//die();
$this->Page->saveAssociated($this->request->data, array("deep" => true));
$this->Session->setFlash("Le contenu a été modifié avec succès", 'notif');
$this->redirect(array("controller"=>"pages","action"=>"index"));
}
if (!$id) {
// si aucun id n'est définit on récupère un enregistrement bidon
$id = $this->Page->getDraftId(array("user_id" => 2));
//debug($id);
$this->backoffice_add_section($id); // on crée une section
$section = $this->Section->find("first",array(
"fields"=>"Section.id",
"conditions"=>array(
"Section.page_id"=>$id,
"Section.draft"=>1
)
));
//debug($section'Section']'id']);
$this->backoffice_add_block($section'Section']'id'], $id); // on crée un block
}
//$d'categories'] = $this->Category->find("list");
$d'categories'] = $this->Category->generateTreeList(null, null, null, ' - ');
$this->set($d);
// on va aller vérifier toutes les sections qui existent
$this->request->data = current($this->Page->find("all", array(
"conditions" => array(
"Page.id" => $id
),
"contain" => array(
"Section" => array(
'Block' => array(
"conditions" => array(
//"Block.draft"=>0
)
)
))
)));
//debug($this->data);
}
Ce qui est plus frustrant, c'est que j'inscris bien mes contenus traduits avec la bonne locale dans la table i18n.
Mais impossible de récupérer correctement ces datas dans ma vue d'édition.
D'ailleurs, dans mon model post, d'après la doc de cake, j'ai la possibilité de nommer mon champ à traduire comme bon me semble.
si je fais ça :
public $actsAs = array(
"Translate"=>array(
"name"=>"_name"
),
'Media.Media' => array(
"extensions" => array('jpg', 'png', 'pdf', 'gif'),
"path" => "/uploads/%y-%m/%f"
),
"Draft.Draft" => array(
"conditions" => array("draft" => 1)
)
);
j'ai mes traductions qui apparaissent dans un tableau indexé
(int) 0 => array(
'Page __i18n__ name_fra' => 'titre fr qui va bien',
'Page __i18n__ name_eng' => 'title uk'
)
Si je change mon model pour quelque chose comme ça
"Translate"=>array(
"name"=>"name_tranlate"
),
et bien je n'ai plus mon tableau de valeurs juste au dessus.
Du coup je ne sais vraiment pas quoi faire.
Si vous avez une idée, je suis vraiment preneur sur ce coup ci !
Fabien