我有一个用户向数据库提交一个字段,它会验证并输入条目。这个新行的主键是自动递增的。CakePHP:如何获取最近创建的自动递增字段
然后,用户将获取到需要新创建的字段的另一个表单。
任何人都可以解决这个问题?
在此先感谢!
我有一个用户向数据库提交一个字段,它会验证并输入条目。这个新行的主键是自动递增的。CakePHP:如何获取最近创建的自动递增字段
然后,用户将获取到需要新创建的字段的另一个表单。
任何人都可以解决这个问题?
在此先感谢!
如果它在数据库中,当你到达下一个表单时,只需在控制器中再次读出它并将其设置为视图变量。
$this->set('lastid', $this->Model->read(null,$id));
或者,如果您需要在数据库中搜索现场使用发现
$this->set('lastid', $this->Model->find('first', array('conditions'=>array('username'=>'MyUserName')) , array('id')));
你可以去周围使用mysql_insert_id()
退房型号:: getInsertID();
// Save the first form
$this->Ingredient->save($newData);
// Get the id of the record just saved
$newIngredientId = $this->Ingredient->id;
// Redirect to a new form
$this->redirect(array(
'controller' => 'dish',
'action' => 'add',
'?' => array('lastId' => $newIngredientId)
));
http://book.cakephp.org/view/1031/Saving-Your-Data, http://book.cakephp.org/view/1442/link
$this->getLastInsertID();
谢谢!很简单,我在想太多。 – junior29101 2010-04-29 21:32:29
我不会使用mysql_insert_id()。它不是便携式的,上班时会很笨重。假设您甚至可以从ConnectionManager获取连接资源。 – 2010-04-29 21:51:03