rendered paste bodyMODEL PRUEBA.PHP:
class Prueba extends AppModel
{
var $name = 'Prueba';
var $validate = array
(
'title' => array
(
'required' => array('rule' => array('minLength', 1), 'message' => 'Required')
),
'content' => array
(
'required' => array('rule' => array('minLength', 1), 'message' => 'Required')
),
);
//var $actsAs = array ();
var $actsAs = array('Translate' => array('title', 'content'));
CONTROLLER ADMIN_ADD:
function admin_add($lang = null)
{
// Layout on this view
$this->layout = 'admin';
// If form is submitted
if (!empty($this->data))
{
$languages = array('spa', 'eng', 'por', 'gal', 'ped');
foreach($languages as $v)
{
$data = array('title' => 'titulerrimo', 'content' => 'Contenterrimo');
if( $id = $this->Model->id ) {
$data['id'] = $id;
}
$this->Prueba->create($data);
$this->Prueba->locale=$v;
$this->Prueba->save($data);
}
}
}
function admin_add($lang = null)
{
// Layout on this view
$this->layout = 'admin';
// If form is submitted
if (!empty($this->data))
{
$this->Prueba->create();
$languages = array('spa', 'eng', 'por', 'gal', 'ped');
foreach($languages as $v)
{
$this->Prueba->locale=$v;
$data = array('title' => 'titulerrimo', 'content' => 'Contenterrimo');
$this->Prueba->save($data);
}
}
}
VISTA (aunque da igual, el $data lo genero en controlador):
<?php echo $form->create('Prueba')."\n";?>
<fieldset>
<legend><?php echo sprintf(__('Add %s', true), __('Prueba', true));?></legend>
<?php
# Spa
echo $form->input('Pruebaspa.title');
echo $form->input('Pruebaspa.content');
# Eng
echo $form->input('Pruebaeng.title');
echo $form->input('Pruebaeng.content');
# Por
echo $form->input('Pruebapor.title');
echo $form->input('Pruebapor.content');
# Gal
echo $form->input('Pruebagal.title');
echo $form->input('Pruebagal.content');
?>
</fieldset>
<?php echo $form->end('Submit')."\n";?>
SQL DEBUG:
1 DESCRIBE `pruebas` 4 4 1
2 DESCRIBE `i18n` 6 6 1
3 INSERT INTO `pruebas` (`modified`,`created`) VALUES ('2008-02-11 17:11:53','2008-02-11 17:11:53') 1 1
4 SELECT LAST_INSERT_ID() AS insertID 1 1 0
5 INSERT INTO `i18n` (`locale`,`model`,`foreign_key`,`field`,`content`) VALUES ('spa','Prueba',6,'title','titulerrimo') 1 0
6 SELECT LAST_INSERT_ID() AS insertID 1 1 0
7 INSERT INTO `i18n` (`locale`,`model`,`foreign_key`,`field`,`content`) VALUES ('spa','Prueba',6,'content','Contenterrimo') 1 0
8 SELECT LAST_INSERT_ID() AS insertID 1 1 0
9 SELECT COUNT(DISTINCT(`Prueba`.`id`)) AS count FROM `pruebas` AS `Prueba` INNER JOIN `i18n` AS `I18nModel` ON (`Prueba`.`id` = `I18nModel`.`foreign_key` AND `I18nModel`.`model` = 'Prueba' AND `I18nModel`.`locale` = 'eng') WHERE `Prueba`.`id` = 6 1 1 1
10 INSERT INTO `pruebas` (`modified`,`created`) VALUES ('2008-02-11 17:11:53','2008-02-11 17:11:53') 1 0
11 SELECT LAST_INSERT_ID() AS insertID 1 1 0
12 INSERT INTO `i18n` (`locale`,`model`,`foreign_key`,`field`,`content`) VALUES ('eng','Prueba',7,'title','titulerrimo') 1 0
13 SELECT LAST_INSERT_ID() AS insertID 1 1 0
14 INSERT INTO `i18n` (`locale`,`model`,`foreign_key`,`field`,`content`) VALUES ('eng','Prueba',7,'content','Contenterrimo') 1 0
15 SELECT LAST_INSERT_ID() AS insertID 1 1 0
16 SELECT COUNT(DISTINCT(`Prueba`.`id`)) AS count FROM `pruebas` AS `Prueba` INNER JOIN `i18n` AS `I18nModel` ON (`Prueba`.`id` = `I18nModel`.`foreign_key` AND `I18nModel`.`model` = 'Prueba' AND `I18nModel`.`locale` = 'por') WHERE `Prueba`.`id` = 7 1 1 1
17 INSERT INTO `pruebas` (`modified`,`created`) VALUES ('2008-02-11 17:11:53','2008-02-11 17:11:53') 1 0
18 SELECT LAST_INSERT_ID() AS insertID 1 1 0
19 INSERT INTO `i18n` (`locale`,`model`,`foreign_key`,`field`,`content`) VALUES ('por','Prueba',8,'title','titulerrimo') 1 0
20 SELECT LAST_INSERT_ID() AS insertID 1 1 0
21 INSERT INTO `i18n` (`locale`,`model`,`foreign_key`,`field`,`content`) VALUES ('por','Prueba',8,'content','Contenterrimo') 1 0
22 SELECT LAST_INSERT_ID() AS insertID 1 1 0
23 SELECT COUNT(DISTINCT(`Prueba`.`id`)) AS count FROM `pruebas` AS `Prueba` INNER JOIN `i18n` AS `I18nModel` ON (`Prueba`.`id` = `I18nModel`.`foreign_key` AND `I18nModel`.`model` = 'Prueba' AND `I18nModel`.`locale` = 'gal') WHERE `Prueba`.`id` = 8 1 1 1
24 INSERT INTO `pruebas` (`modified`,`created`) VALUES ('2008-02-11 17:11:53','2008-02-11 17:11:53') 1 0
25 SELECT LAST_INSERT_ID() AS insertID 1 1 0
26 INSERT INTO `i18n` (`locale`,`model`,`foreign_key`,`field`,`content`) VALUES ('gal','Prueba',9,'title','titulerrimo') 1 0
27 SELECT LAST_INSERT_ID() AS insertID 1 1 0
28 INSERT INTO `i18n` (`locale`,`model`,`foreign_key`,`field`,`content`) VALUES ('gal','Prueba',9,'content','Contenterrimo') 1 0
29 SELECT LAST_INSERT_ID() AS insertID 1 1 0
30 SELECT COUNT(DISTINCT(`Prueba`.`id`)) AS count FROM `pruebas` AS `Prueba` INNER JOIN `i18n` AS `I18nModel` ON (`Prueba`.`id` = `I18nModel`.`foreign_key` AND `I18nModel`.`model` = 'Prueba' AND `I18nModel`.`locale` = 'ped') WHERE `Prueba`.`id` = 9 1 1 1
31 INSERT INTO `pruebas` (`modified`,`created`) VALUES ('2008-02-11 17:11:53','2008-02-11 17:11:53') 1 6
32 SELECT LAST_INSERT_ID() AS insertID 1 1 0
33 INSERT INTO `i18n` (`locale`,`model`,`foreign_key`,`field`,`content`) VALUES ('ped','Prueba',10,'title','titulerrimo') 1 0
34 SELECT LAST_INSERT_ID() AS insertID 1 1 0
35 INSERT INTO `i18n` (`locale`,`model`,`foreign_key`,`field`,`content`) VALUES ('ped','Prueba',10,'content','Contenterrimo') 1 0
36 SELECT LAST_INSERT_ID() AS insertID 1 1 0