学生HasMany支付和支付属于学生。在创建付款时,我必须指明我为此付款创建的学生。我希望能够在创建付款时访问学生的ID,以便操作add()方法中的某些内容。访问控制器方法变量CAKEPHP
我在我的控制器中有一个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'中 –