您好我正在使用Yii框架并尝试从视图中提交我的数据,但它出现错误,Undefined index表示,这里是printcreen:
代码是:
这是我的模特:
<?php
class ConfirmPayment extends CActiveRecord{
public $nomorPemesanan; //nomorpemesanan
public $bankAsal; // nama bank asal
public $pemilikRekAsal; // nama pemilik rek asal
public $bankTujuan; //nama bank tujuan transfer
public $nominalTransfer; // nominal transfer / jumlah uang yang di transfer
public $dataPaymentText;
public static function model($className = __CLASS__){
return parent::model($className);
}
public function tableName(){
return 'tbl_confirm_payment';
}
public function afterFind(){
parent::afterFind();
$this->dataPaymentText = explode('#',$this->text_detail);
}
public function rules(){
return array(
array('order_code,text_detail','required'),
array('nomorPemesanan,bankAsal,pemilikRekAsal,bankTujuan,nominalTransfer','required'),
);
}
public function attributeLabels(){
return array(
'id'=>'ID Konfirmasi',
'nomorPemesanan'=>'Nomor Pemesanan',
'pemilikRekAsal'=>'Nama Pemilik Rekening Asal',
'bankAsal'=>'Nama Bank Asal',
'bankTujuan'=>'Bank Tujuan Transfer',
'nominalTransfer'=>'Jumlah yang ditransfer',
);
}
}
这是我的控制器:
public function actionOrders($id = '')
{
// component IsAuth
IsAuth::Customer();
// konfirmasi pembayaran
if (isset($_GET['confirm']))
{
// panggil model Confirmpayment
$model = new ConfirmPayment;
// jika data ConfirmPayment dikirim dengan method $_POST
if (isset($_POST['ConfirmPayment']))
{
// set value field
$order_code = $_POST['ConfirmPayment']['nomorPemesanan'];
$model->attributes = $_POST['ConfirmPayment'];
$model->order_code = $_POST['ConfirmPayment']['nomorPemesanan'];
$model->text_detail .= $_POST['ConfirmPayment']['bankAsal'] . '#';
$model->text_detail .= $_POST['ConfirmPayment']['pemilikRekAsal'] . '#';
$model->text_detail .= $_POST['ConfirmPayment']['bankTujuan'] . '#';
$model->text_detail .= $_POST['ConfirmPayment']['nominalTransfer'] . '#';
// jika data confirmPayment disimpan maka
if ($model->save())
{
// find data order by attributes berdasarkan order_code
$modelOrder = Order::model()->findByAttributes(array('order_code' => $order_code));
// set field payment_status dari 0 menjadi 1, artinya pembayaran sudah dikonfirmasi
$modelOrder->payment_status =1;
exit(CActiveForm::validate($modelOrder));
// simpan
$modelOrder->save();
// setFlash konfirmasi pembayaran sukses
Yii::app()->user->setFlash('success', 'Belanjaan dengan nomor pesanan #'.$order_code.' berhasil dikonfirmasi!');
// redirect
$this->redirect(array('orders'));
return;
}
}
// render ke file customer/confirm_payment
$this->render('confirm_payment', array('model' => $model));
return;
}
// untuk view list_orders
if (empty($id))
{
// panggil model Order dan function search
$model = new Order('search');
// hapus default values pada attributes
$model->unsetAttributes();
// untuk filter data Order berdasarkan id customer
$model->customer_id = Yii::app()->user->customerId;
// jika data order dikirim view get
if (isset($_GET['Order']))
{
// set attributes untuk pencarian
$model->attributes = $_GET['Order'];
}
// render ke file customer/list_orders
$this->render('list_orders', array('model' => $model));
return;
}
// untuk view detail_order
if (!empty($id))
{
// join query untuk mendapatkan detail_order
$dataOrderDetail = Yii::app()->db->createCommand()
->select('tbl_orders.*,tbl_orderdetail.*,tbl_products.*')
->from('tbl_orders')
->join('tbl_orderdetail', 'tbl_orderdetail.order_id = tbl_orders.id')
->join('tbl_products', 'tbl_products.id = tbl_orderdetail.product_id')
->where('tbl_orders.id=:id_order', array(':id_order' => $id))
->queryAll();
// join query untuk mendapatkan data order dan customer
$dataOrder = Yii::app()->db->createCommand()
->select('tbl_orders.*, tbl_customer.customer_name')
->from('tbl_orders')->join('tbl_customer', 'tbl_orders.customer_id = tbl_customer.id')
->where('tbl_orders.id=:id', array(':id' => $id))
->queryRow();
// render ke view customer/detail_order
$this->render('detail_order', array(
'dataOrder' => $dataOrder,
'orderDetail' => $dataOrderDetail,
'subtotal' => '',
'grandtotal' => '',
));
return;
}
和我的观点:
<div style="padding:5px 10px 0 0;margin:5px 5px 15px 5px; border:1px solid #CCC;text-align: justify;">
<div style="clear: left;"></div>
<?php echo CHtml::beginForm(); ?>
<?php echo CHtml::errorSummary($model); ?>
<table>
<tr>
<td><?php echo CHtml::activeLabel($model, 'nomorPemesanan'); ?></td>
<td>:</td>
<td><b><?php echo $_GET['confirm']; ?></b></td>
</tr>
<tr>
<td><?php echo CHtml::activeLabel($model, 'bankAsal'); ?></td>
<td>:</td>
<td><b><?php echo CHtml::activeTelField($model, 'bankAsal'); ?></b></td>
</tr>
<tr>
<td><?php echo CHtml::activeLabel($model, 'pemilikRekAsal'); ?></td>
<td>:</td>
<td><b><?php echo CHtml::activeTextField($model, 'pemilikRekAsal'); ?></b></td>
</tr>
<tr>
<td><?php echo CHtml::activeLabel($model, 'bankTujuan'); ?></td>
<td>:</td>
<td>
<select name="Confirmpayment[bankTujuan]">
<option value="BCA 1700-******* a.n. L******">BCA 1700-******* a.n. L******</option>
<option value="Mandiri 150-00-********* L****** Jr">Mandiri 150-00-********* a.n. L******</option>
<option value="BNI 1580****** a.n. L******">BNI 1580****** a.n. L******</option>
</select>
</td>
</tr>
<tr>
<td><?php echo CHtml::activeLabel($model, 'nominalTransfer'); ?></td>
<td>:</td>
<td><b><?php echo CHtml::activeTelField($model, 'nominalTransfer'); ?></b></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><?php echo CHtml::submitButton('Konfirmasi'); ?></td>
</tr>
</table>
<?php echo CHtml::endForm(); ?>
<div style="clear: both;"> </div>
希望有人能解决这个问题..提前致谢!
答案 0 :(得分:5)
您的表单中没有nomorPemesanan活动文本字段。
您可以尝试以这种方式更新表单:
<tr>
<td><?php echo CHtml::activeLabel($model, 'nomorPemesanan'); ?></td>
<td>:</td>
<td><b><?php echo CHtml::activeTextField($model, 'nomorPemesanan'); ?></b></td>
</tr>