【发布时间】:2014-02-06 04:13:53
【问题描述】:
学生有许多付款和付款属于学生。创建付款时,我必须指出我正在为哪个学生创建此付款。我希望能够在创建付款时访问学生的 id,以便在 add() 方法中操作某些内容。
我的控制器中有一个 add() 方法。这是 add() 的当前代码。
public function add() {
if ($this->request->is('post')) {
$this->Payment->create();
if ($this->Payment->save($this->request->data)) {
$this->Session->setFlash(__('The payment has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The payment could not be saved. Please, try again.'));
}
}
$students = $this->Payment->Student->find('list');
$this->set(compact('students'));
}
付款方式代码
<?php echo $this->Form->create('Payment'); ?>
<fieldset>
<legend><?php echo __('Add Payment'); ?></legend>
<?php
echo $this->Form->input('student_id');
echo $this->Form->input('date');
echo $this->Form->input('total', array('default' => '0.0'));
echo $this->Form->input('notes');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
【问题讨论】:
-
您可以在视图中添加支付表单的代码吗?如果您以该形式选择学生,则应将其包含在
$this->request->data
标签: cakephp