hola comunidad en yii ¿¿ soy nuevo esto pero tengo una duda tengos dos una tabla producto y tabla orden ya hice las relaciones y me carga los datos pero en Cgridview de el admin.php orden producto necesito que me salga asi
es decir que los nombre de los producto sea una columnas mas de cgridview
id producto id orden nombre_Producoto1 nombre_Producto2 ----> header cabecera
001 001 CantidadProducto1 CantidadProducto2
otro ejemplo
id producto id orden Cocacola Pepsi
001 001 100 50
Tabla producto {
id_Producto
Nombre_Producto
Cantidad_Producto
}
tabla orden_producto
{
Id_Producto
id_orden
o
}
Tabla orden {
id_orden
Nombre_Producto
Cantidad_Producto
}
CODIGO DEL MODELO ORDEN_pRODUCTO
*/
class OrdenP extends CActiveRecord
{
public $CantidadOrden;
public $Nombre_Producto;
public $Cantidad_Producto;
public $Hora_Final;
public $Hora_Inicio;
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'orden_p';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('id_orden, id_producto', 'required'),
array('id_orden, id_producto', 'numerical', 'integerOnly'=>true),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, id_orden, id_producto', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'idOrden' => array(self::BELONGS_TO, 'Orden', 'id_orden'),
'idProducto' => array(self::BELONGS_TO, 'Producto', 'id_producto'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'id_orden' => 'Id Orden',
'id_producto' => 'Id Producto',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('id_orden',$this->id_orden);
$criteria->compare('id_producto',$this->id_producto);
$criteria->with = array('idOrden', 'idProducto');
$criteria->compare('idProducto.NombreProducto',$this->Nombre_Producto,true);
$criteria->compare('idorden.Hora_Inicio',$this->Hora_Inicio,true);
$criteria->compare('idorden.Hora_Final',$this->Hora_Final,true);
$criteria->compare('idOrden.Cantidad_litro', $this->CantidadOrden,true);
$criteria->compare('idProducto.Cantidad_Producto',$this->Cantidad_Producto,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public static function getProducto ()
{
return CHtml::ListData(Producto::model()->FindAll(),'Codigo_Producto','Nombre_Producto');
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return OrdenP the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
VIEW DE ORDEN prODUCTO
<?php
/* @var $this OrdenPController */
/* @var $model OrdenP */
$this->breadcrumbs=array(
'Orden Ps'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List OrdenP', 'url'=>array('index')),
array('label'=>'Create OrdenP', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript(‘search’, "
$(’.search-button’).click(function(){
$('.search-form').toggle();
return false;
});
$(’.search-form form’).submit(function(){
$('#orden-p-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Manage Orden Ps</h1>
<p>
You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>
<?php echo CHtml::link(‘Advanced Search’,’#’,array(‘class’=>‘search-button’)); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial(’_search’,array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
'id'=>'orden-p-grid',
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id_orden',
'id_producto',
array(
'name'=> 'Nombre_Producto',
'value'=>'$data->idProducto->Nombre_Producto',
),
array(
'name'=>'CantidadOrden',
'value'=>'$data->idOrden->Cantidad_litro',
),
array(
'name'=>'Cantidad_Producto',
'value'=>'$data->idProducto->Cantidad_Producto',
),
array
(
'name'=>'Hora_Inicio',
'value'=>'$data->idOrden->Hora_Inicio',
),
array
(
'name'=>'Hora_Final',
'value'=>'$data->idOrden->Hora_Final',
),
array(
‘name’=>‘Nombre_Producto’,
‘value’=>’$data->idProducto->Nombre_Producto’, //Con esto se mostrará la descripción de la categoría en vez del id_categoria
‘filter’=> OrdenP::getProducto(), //Esto ya es un agregado, muestra un combobox con todas las categorias para poder filtrarlas, si no lo ponemos usa el id_categoria por defecto
//Debemos de crear una función estática en el modelo Categorias que se llame getListCategorias(), esto es totalmente opcional
),
array(
'class'=>'CButtonColumn',
),
),
)); ?>