我有 2 个相关的模型,我想做的是在我的添加视图中我想将 id 字段设置为隐藏字段,以便它不会显示在我的添加视图中,当我将其设置为隐藏时表单不会不提交。有没有办法将 id 值作为隐藏字段传递?
这是我的添加视图
<?php echo $this->Form->create('ItQueryComment'); ?>
<?php echo __('Add It Query Comment'); ?>
<?php
echo $this->Form->hidden('it_query_id');
echo $this->Form->input('comment');
?>
<?php echo $this->Form->end(__('Submit')); ?>
这是 ItQueries 控制器的添加功能
public function add() {
if ($this->request->is('post')) {
$this->ItQuery->create();
if ($this->ItQuery->save($this->request->data)) {
$this->Session->setFlash(__('The it query has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The it query could not be saved. Please, try again.'));
}
}
$itQueryTypes = $this->ItQuery->ItQueryType->find('list');
$this->set(compact('itQueryTypes'));
}
先感谢您