學生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'中 –