2015-02-10 76 views
0

我是CakePHP领域的新手。 我尝试执行Post教程并向数据库添加了一个额外的表。 我想添加记录到第二个表,第一个表(帖子)正在工作,但第二个(猫)没有。在一个应用程序中使用两个或三个表

看起来这个表格是空的。 我没有收到错误,它停留在输入页面上。

有没有人可以帮忙?

VIEW

<?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); 
    } 
+0

有您创建了一个猫的模式?另外,在你的控制器中,你有if($ this-> request->是('cat');它应该是if($ this-> request->是('post');这里所指的帖子是指Http Verb POST,而不是本教程的Post模型,if语句正在检查一个表单是否已经发布给控制器,如果有,它将尝试保存数据。 – 2015-02-10 21:12:06

回答

0

您需要使用白水或saveAssociated如果模型链接到另一个模型。 取决于你的表看怎么样

0

当你创建你需要把模型的名字里面的一种形式:

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