Reputation: 55
I'am a French developer so sorry for my bad english.
I have a problem when inserting data in multiple languages on my site. I said that my i18n table was created from the console and inserted on a single language it works!
This is the error:
Database Error
Error: SQLSTATE [42S22]: Column not found: 1054 Unknown column 'Array' in 'field list'
SQL Query: INSERT INTO ` expandingCakePHP. Accesses
(name
) VALUES (Array)
Notice: If you want to customize this error message, create app / View / Errors / pdo_error.ctp
My admin_add.ctp (file View / Accesses)
foreach (Configure :: read ('Config.languages') as $lang) {
echo $this-> Form-> input ('Access.name.'. $lang, array ('label' => __ ('Name'). '(. $lang.') '));
}
My access.php (Model File)
var $actsAs = array (
'Translate' => array (
'name' => '_name'
)
);
My AccessesController.php (Controller folder)
admin_add public function () {
if ($this-> request-> is ('post')) {
$this-> Access-> create ();
$this-> Access-> locale = Configure :: read ('Config.languages');
if ($this-> Access-> save ($ this-> request-> data)) {
$this-> Session-> setFlash (__ ('The access has been saved'), 'notif');
$this-> redirect (array ('action' => 'index'));
}
else {
$this-> Session-> setFlash (__ ('The Access Could not be saved. Please, try again.'), 'notif', array ('type' => 'alert-error'));
}
}
}
In my bootstrap.php (Config file)
Configure :: write ('Config.languages', array ('eng', 'eng'));
Configure :: write ('Config.language', 'eng');
Configure :: write ('App.encoding', 'utf-8');
The structure received by the post form is correct? / app / Controller / AccessesController.php (line 46)
array (
'Access' => array (
'name' => array (
'eng' => 'title',
'eng' => 'title'
)
)
)
Upvotes: 0
Views: 586
Reputation: 1535
Please use $this->Model->saveAll($this->request->data);
instead of $this->Model->save($this->request->data);
Upvotes: 0
Reputation: 572
The post structure seems wrong, e.g. see http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveassociated-array-data-null-array-options-array
It should be more like:
array (
'Access' => array (
'name' => 'a name',
'title' => 'a title',
'another model' => array(...)
)
)
)
Upvotes: 0