我有一个库存表。现在,使用此表,我想在Tbgridview中显示Pharmacy模块上的数据,以便它只显示Pharmacy商店中的那些库存。即行category_id=2
。
如何,我可以在药物的索引页面上这样做。这是Pharmacy索引页面的代码。
<?php
$this->menu=array(
array('label'=>'Add Drug', 'icon'=>'icon-plus', 'url'=>Yii::app()->controller->createUrl('create'), 'linkOptions'=>array()),
array('label'=>'List Drugs', 'icon'=>'icon-th-list', 'url'=>Yii::app()->controller->createUrl('index'),'active'=>true, 'linkOptions'=>array()),
array('label'=>'List Orders', 'icon'=>'icon-th-list', 'url'=>Yii::app()->controller->createUrl('PhOrder/index'), 'linkOptions'=>array()),
array('label'=>'List Distributors', 'icon'=>'icon-th-list', 'url'=>Yii::app()->controller->createUrl('PhDistributor/index'), 'linkOptions'=>array()),
);
?>
<div>
<?php ?>
<?php
$model= new Inventory;
$this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'ph-drug-grid',
'dataProvider'=>$model->search(),
'type'=>'bordered condensed',
'template'=>'{summary}{pager}{items}{pager}',
'columns'=>array(
array(
'header'=>'<a href="#">S. N. </a>',
'value'=>'$data->inventory_code',
'type'=>'raw',
),
'description',
'manufacturer',
'minimum_order_level',
'store_id',
'stock_quantity',
array(
'header'=>'<a>Actions</a>',
'class'=>'bootstrap.widgets.TbButtonColumn',
'template' => '{dispose}',
'buttons' => array(
'dispose' => array(
'label'=>'Dispose',
'options'=>array(
'class'=>'btn btn-small',
'onclick'=>'return confirm("Are you sure, you want to dispose this drug?")'
),
)
),
'htmlOptions'=>array('nowrap'=>'nowrap'),
)
),
)); ?>
</div>
答案 0 :(得分:1)
设置模型的属性,然后如果在模型search()
的{{1}}函数中对其进行过滤,则结果将被过滤
Inventory
答案 1 :(得分:1)
您也可以在控制器中使用CSqlDataProvider
$sql='select * from inventory where category_id=2';
$count=Yii::app()->db->createCommand('select count(*) from inventory where category_id=2')->queryScalar();
$dataProvider = new CSqlDataProvider($sql, array(
'totalItemCount'=>$count,
'keyField' => 'id',
'pagination'=>array(
'pageSize'=>10,
),
));