Wrap text
|
|
Schema:
Announcement:
tableName: announcement
actAs:
Timestampable: ~
columns:
id:
type: integer(9)
primary: true
autoincrement: true
created_at:
type: timestamp
updated_at:
type: timestamp
user_id:
type: integer(9)
AnnouncementI18n:
tableName: announcement_i18n
columns:
announcement_id:
type: integer(9)
lang:
type: string(2)
title:
type: string(80)
body:
type: string(4000)
relations:
Announcement:
foreignAlias: translation
onDelete: cascade
-------------------------------------------
module action:
class i18nActions extends sfActions
{
/**
* Executes index action
*
*/
public function executeIndex()
{
$announ = new Announcement();
$announ->user_id = 1;
$announ->translation[0]->title = 'Titre de la version française';
$announ->translation[0]->body = 'Corps de la version française';
$announ->translation[0]->lang = 'fr';
$announ->translation[1]->title = 'Title english version';
$announ->translation[1]->body = 'Body english version';
$announ->translation[1]->lang = 'en';
$announ->save();
}
public function executeShow()
{
$this->announ = Doctrine_Query::create()
->from('Announcement a')
->leftJoin('a.translation t')
->where('a.id = ? AND t.lang = ?')
->fetchOne(array(1, 'fr'));
}
public function executeUpdate()
{
/* Values for test */
$trans = array(
'fr' => array('title' => 'Titre en français', 'body' => 'Corps en français'),
'en' => array('title' => 'English Title', 'body' => 'English Body')
);
$announ = Doctrine_Query::create()
->from('Announcement a')
->leftJoin('a.translation t')
->where('a.id = ?')
->fetchOne(array(1));
for($i = 0; $i <= (count($announ->translation)-1); $i++)
{
$announ->translation[$i]->title = $trans[$announ->translation[$i]->lang]['title'];
$announ->translation[$i]->body = $trans[$announ->translation[$i]->lang]['body'];
}
$announ->state('DIRTY');
$announ->save();
$this->announ = $announ;
}
}
|