Yii Widgets CGridView show data -


i have 2 tables in db: t_product , t_user.

t_user

'***************************************************************************'

'* cod_arm * descrição * username * password * salt * tipo *'

'***************************************************************************'

'* 000 * 000 - admin * admin * 123 * asdfgh * *'

'* 001 * 001 - medicina 1 * p01 * 123 * asdf * u *'

'* 021 * 021 - urologia * p21 * 123 * asdfg * u *'

****************************************************************************'

t_product

'*********************************************************************************************'

'* id_prod * cod_art * designacao * unidade * data_validade * cod_loc *'

'*********************************************************************************************'

'* 1 * 210110300 * adesivo comum (...) * rol * 2014-11-30 * p010101 *'

'* 2 * 210110320 * adesivo comum (...) * rol * null * p01 *'

'* 3 * 210110302 * adesivo comum (...) * rol * 2016-12-30 * p210110 *'

'* 4 * 210110301 * adesivo comum (...) * rol * 2014-11-30 * p010101 *'

'* 1 * 210110300 * adesivo comum (...) * rol * 2014-11-30 * p01ext *'

'* 1 * 210110300 * adesivo comum (...) * rol * 2014-11-30 * p210101 *'

'***********************************************************************************************'

i want, when user click in "manage product". table show products where cod_loc 'username%'.

exemp: in case user "p01". in page-"manage produtos" want show products cod_loc beginning "p01".

i try whith dataprovider. in model->product .. cannot show want! can show products cod_loc match username (ex."p01") , can show products cod_loc have "p","0" , "1", , case produts.


well, in model product have code:

<?php    /**   * model class table "produto".   *   * followings available columns in table 'produto':   * @property integer $idproduto   * @property integer $cod_art   * @property string $designacao   * @property string $unidades   * @property string $data_validade   * @property string $cod_loc   * @property string $username   *   * followings available model relations:   * @property user $username0   */  class produto extends cactiverecord  {  	/**  	 * @return string associated database table name  	 */  	public function tablename()  	{  		return 'produto';  	}    	/**  	 * @return array validation rules model attributes.  	 */  	public function rules()  	{  		// note: should define rules attributes  		// receive user inputs.  		return array(  			array('cod_art, designacao, unidades, cod_loc', 'required'),  			array('cod_art', 'numerical', 'integeronly'=>true),  			array('designacao', 'length', 'max'=>128),  			array('unidades', 'length', 'max'=>6),  			array('cod_loc', 'length', 'max'=>12),  			array('username', 'length', 'max'=>3),  			array('data_validade', 'safe'),  			// following rule used search().  			// @todo please remove attributes should not searched.  			array('idproduto, cod_art, designacao, unidades, data_validade, cod_loc, username', 'safe', 'on'=>'search'),  		);  	}    	/**  	 * @return array relational rules.  	 */  	public function relations()  	{  		// note: may need adjust relation name , related  		// class name relations automatically generated below.  		return array(  			'username0' => array(self::belongs_to, 'user', 'username'),  		);  	}    	/**  	 * @return array customized attribute labels (name=>label)  	 */  	public function attributelabels()  	{  		return array(  			//'idproduto' => 'id produto',  			'cod_art' => 'cod art',  			'designacao' => 'designacao',  			'unidades' => 'unidades',  			'data_validade' => 'data validade',  			'cod_loc' => 'cod loc',  			//'username' => 'username',  		);  	}    	/**  	 * retrieves list of models based on current search/filter conditions.  	 *  	 * typical usecase:  	 * - initialize model fields values filter form.  	 * - execute method cactivedataprovider instance filter  	 * models according data in model fields.  	 * - pass data provider cgridview, clistview or similar widget.  	 *  	 * @return cactivedataprovider data provider can return models  	 * based on search/filter conditions.  	 */  	public function search()  	{  		// @todo please modify following code remove attributes should not searched.    		//$criteria=new cdbcriteria;    		/*$criteria->compare('cod_arm',$this->cod_arm);  		$criteria->compare('descricao',$this->descricao,true);  		$criteria->compare('username',$this->username,true);  		$criteria->compare('password',$this->password,true);  		$criteria->compare('salt',$this->salt,true);  		$criteria->compare('tipo',$this->tipo,true);*/                  $username = yii::app()->user->name;  		return new cactivedataprovider('produto', array(                      'criteria'=>array(                      'condition'=>'cod_loc :username%',                      'params' => array(                          ':username'=>$username                      )                  ),              ));  	}    	/**  	 * returns static model of specified ar class.  	 * please note should have exact method in cactiverecord descendants!  	 * @param string $classname active record class name.  	 * @return produto static model class  	 */  	public static function model($classname=__class__)  	{  		return parent::model($classname);  	}  }


and in views>produto>admin.php have code:

<?php  /* @var $this produtocontroller */  /* @var $model produto */    $this->breadcrumbs=array(  	'produtos'=>array('index'),  	'manage',  );    $this->menu=array(  	array('label'=>'list produto', 'url'=>array('index')),  	array('label'=>'create produto', 'url'=>array('create')),  );    yii::app()->clientscript->registerscript('search', "  $('.search-button').click(function(){  	$('.search-form').toggle();  	return false;  });  $('.search-form form').submit(function(){  	$('#produto-grid').yiigridview('update', {  		data: $(this).serialize()  	});  	return false;  });  ");  ?>    <h1>manage produtos</h1>    <p>  may optionally enter comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>  or <b>=</b>) @ beginning of each of search values specify how comparison should 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 -->  <?php echo $ap = yii::app()->user->name; ?>  <?php $this->widget('zii.widgets.grid.cgridview', array(  	'id'=>'produto-grid',  	'dataprovider'=>$model->search(),  	'filter'=>$model,  	'columns'=>array(  		//'idproduto',  		'cod_art',  		'designacao',  		'unidades',  		'data_validade',  		'cod_loc',  		/*  		'username',  		*/  		array(  			'class'=>'cbuttoncolumn',  		),  	),  )); ?>

in mysql, can want -> select * produto cod_loc 'username%';

not going in code answer may in code example:

$username = 'p01' ; product::model()->findall('cod_loc :username', array(     ':username'=>"{$username}%" )); 

or in data provider:

$dataprovider = new cactivedataprovider('product', array(     'criteria'=>array(         'condition'=>'cod_loc :username',         'params' => array(             ':username'=>"{$username}%"         )     ), )); 

by product mean model class t_product table.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -