CakePHP saveAll与belongsTo关系的问题

时间:2013-11-06 12:13:40

标签: cakephp cakephp-2.3

我有模型TranslationSection,TranslationItem和TranslationContent

class TranslationSection extends AppModel {
    public $belongsTo = array(
            'TranslationCategory'
        );
    public $hasMany = array(
            'TranslationItem'
        );
}
class TranslationItem extends AppModel {
    public $hasMany = array(
            'TranslationContent'
        );
    public $hasOne = array(
            'TranslationSection'
        );
}
class TranslationContent extends AppModel {
    public $hasOne = array(
            'TranslationItem',
            'TranslationLanguage'
        );
}

我正在使用表单助手来编辑TranslationContent,这个表单会正确填充。

<?php echo $this->Form->create('TranslationContents'); ?>
    <fieldset>
        <legend>Edit Contents for "<?= $this->request->data["TranslationSection"]["name"];?>"</legend>
        <?php 
        foreach($this->request->data["TranslationItem"] as $key => $item){
            echo '<h2>'.$item["caption"].'</h2>';
            $i = 0;
            foreach($translationsLanguages as $language_id => $language){
                echo '<h3>'.$language.'</h3>';
                echo $this->Form->input('TranslationItem.'.$key.'.TranslationContent.'.$i.'.content');
                echo $this->Form->input('TranslationItem.'.$key.'.TranslationContent.'.$i.'.id', array('type' => 'hidden'));
                echo $this->Form->input('TranslationItem.'.$key.'.TranslationContent.'.$i.'.translation_item_id', array('type' => 'hidden'));
                echo $this->Form->input('TranslationItem.'.$key.'.TranslationContent.'.$i.'.translation_language_id', array('type' => 'hidden'));
                $i ++;
            }

            echo $this->Form->input('TranslationItem.'.$key.'.id', array('type' => 'hidden'));
        }
        ?>
    </fieldset>
    <?php echo $this->Form->end(__('Submit')); ?>

我正在尝试保存数据,蛋糕说一切都正确保存,然而,没有任何更新。

if ($this->TranslationItem->saveAll($this->request->data["TranslationItem"])) {
                $this->Session->setFlash(__('Your Section has been updated.'));
                return $this->redirect(array('action' => 'index'));
            }
            $this->Session->setFlash(__('Unable to update your Section.'));

我出错的任何想法?我认为结构是正确的,因为表格填充正确。

0 个答案:

没有答案