在一个应用程序中使用两个或三个表

时间:2015-02-10 20:06:04

标签: mysql cakephp

我是CakePHP的新手。 我尝试做Post教程并在数据库中添加了一个额外的表。 我想将记录添加到第二个表,第一个表(帖子)正在工作,但第二个表(猫)没有。

表单似乎是空的。 我没有收到错误,它停留在输入页面上。

有人可以提供帮助吗?

查看

<?php
echo $this->Form->create('cat_cat');
echo $this->Form->input('naam_cat');
echo $this->Form->input('Omschrijving_cat', array('rows' => '3'));

echo $this->Form->input('image_cat', array('type' => 'file'));

echo $this->Form->end('Save Cat');

?>

CatsController
public function operation() {
            if ($this->request->is('cat')) {
    $this->Cat->create();
    if ($this->Cat->save($this->request->data)) {
    $this->Session->setFlash(__('Your cat has been saved.'));
    return $this->redirect(array('action' => 'nosores2'));
    }
    $this->Session->setFlash(__('Unable to add your cat.'));
    }
    }





public function detail($id) {
    if (!$id) {
        throw new NotFoudExeption(__('Invalid cat'));
    }

    $cat = $this->Cat->findById($id);
    if (!$cat) {
        throw new NotFoundException(__('Invalid cat'));
    $this->set('cat', $cat);
    }

2 个答案:

答案 0 :(得分:0)

如果模型链接到另一个模型,则需要使用saveAll或saveAssociated。 取决于你的表格如何

答案 1 :(得分:0)

创建表单时,需要放入模型名称:

echo $this->Form->create('Cat');
相关问题