0

我有模型 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.'));

有什么想法我哪里出错了吗?我认为结构是正确的,因为表单被正确填充。

4

0 回答 0