【问题标题】:CakePHP and Translate BehaviorCakePHP 和翻译行为
【发布时间】:2013-01-14 17:27:13
【问题描述】:

我是一名法国开发人员,很抱歉我的英语不好。

在我的网站上插入多种语言的数据时出现问题。 我说过我的 i18n 表是从控制台创建的,并以它可以工作的单一语言插入!

这是错误:

数据库错误

错误:SQLSTATE [42S22]:未找到列:1054 “字段列表”中的未知列“数组” SQL 查询:INSERT INTO ` expandingCakePHP. Accesses(name) 值(数组) 注意:如果要自定义这个错误信息,创建app/View/Errors/pdo_error.ctp

我的 admin_add.ctp(文件查看/访问)

foreach (Configure :: read ('Config.languages​​') as $lang) {
echo $this-> Form-> input ('Access.name.'. $lang, array ('label' => __ ('Name'). '(. $lang.') '));
}

我的 access.php(模型文件)

var $actsAs = array (
   'Translate' => array (
      'name' => '_name'
   )
);

我的 AccessesController.php(控制器文件夹)

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'));
      }
   }
}

在我的 bootstrap.php(配置文件)中

Configure :: write ('Config.languages​​', array ('eng', 'eng'));
Configure :: write ('Config.language', 'eng');
Configure :: write ('App.encoding', 'utf-8');

post 表单收到的结构是否正确? /app/Controller/AccessesController.php(第46行)

array (
   'Access' => array (
      'name' => array (
         'eng' => 'title',
         'eng' => 'title'
      )
   )
)

【问题讨论】:

    标签: cakephp internationalization cakephp-2.0


    【解决方案1】:

    使用这个

     $this->Model->save($this->request->data,false);
    

    【讨论】:

      【解决方案2】:

      帖子结构似乎错误,例如见http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveassociated-array-data-null-array-options-array

      应该更像:

      array (
         'Access' => array (
            'name' => 'a name',
            'title' => 'a title',
            'another model' => array(...)
            )
         )
      )
      

      【讨论】:

        【解决方案3】:

        请使用$this->Model->saveAll($this->request->data);

        而不是$this->Model->save($this->request->data);

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-07-09
          • 2010-10-19
          • 2019-02-01
          相关资源
          最近更新 更多