Hi,
I am very new to Yii and trying to build an order management system, I am stuck with displaying an order where i need to display list of ordered items in order view page by passing default order_idn.
Can anyone guide me on this?
Order header info stored in : Order table -> order_idn (pk)
Ordered Product details stored in : map_order_details -> order_idn (fk)
Order Model:
relationship added as follow
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
'maporderproduct' => array(self::HAS_MANY, 'MapOrdersProduct', 'order_idn'),
);
}
OrderController.php
public function actionView($id)
{
//$this->render('view',array(
// 'model'=>$this->loadModel($id),
//));
//$dataProvider=new CActiveDataProvider('InvoiceTransaction');
//$dataProvider=new CActiveDataProvider('InvoiceTransaction');
$model=$this->loadModel($id);
$dataProvider=new MapOrdersProduct('search');
$dataProvider->unsetAttributes(); // clear any default values
if(isset($_GET['MapOrdersProduct']))
$dataProvider->attributes=$_GET['MapOrdersProduct'];
$dataProvider->orders_idn=$model->orders_idn;/// this line only gave me answer
//$model->unsetAttributes();
if(isset($_GET['Orders']))
$dataProvider->attributes=$_GET['Orders'];
$this->render('view',array(
'model'=>$model,'dataProvider'=>$dataProvider,
));
}
Order\view.php
<h1>View Orders #<?php echo $model->orders_idn; ?></h1>
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'orders_idn',
//'request_idn',
'order_form_no',
array(
'name'=>'order_dt',
'value'=>date_format(new DateTime($model->order_dt),"m/d/Y H:i:s")
),
array(
'name'=>'expected_dt',
'value'=>date_format(new DateTime($model->expected_dt),"m/d/Y H:i:s")
),
array(
'name'=>'dealer_idn',
'value'=>$model->dealer->first_name,
),
),
));
?>
<?php
/* ordered product list */
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'map-orders-product-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'map_orders_product_idn',
array(
'name'=>'orders_idn',
'visible'=>false
),
array(
'name'=>'first_name',
'value'=>'$data->dealer->first_name',
),
array(
'name'=>'code_product_ctgy_desc',
'value'=>'$data->productctgy->code_product_ctgy_desc',
),
array(
'name'=>'code_product_ctgy_type_desc',
'value'=>'$data->productctgytype->code_product_ctgy_type_desc',
),
//'product_idn',
array(
'name'=>'product_desc',
'value'=>'$data->product->product_desc',
),
),
)); ?>
Expected output of the view page is attached.
Please guide me on this.
Thanks,
Thani.