Yii Framework Forum: Cgridview from the other model - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cgridview from the other model Rate Topic: -----

#1 User is offline   loper_kesasar 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 31-March 11

Posted 17 November 2011 - 10:58 AM

Hello guys i need your help,,
i want to show in my model view the personal detail and children that they have
like this
<h1>View Lksa  <?php echo $model->lksa_name; ?></h1>

<?php $this->widget('zii.widgets.CDetailView', array(
	'data'=>$model,
	'attributes'=>array(
		//'id',
		'year',
		'lksa_code',
		'lksa_name',
		'address',
		'regency.regency_name',
		array(
		    'label'=>'Provinsi',
		    'value'=>$model->regency->province->province_name,
		),
		'email',
		'leader',
		'ownershipStatus.owner',
		'contact_person',
		'handphone_number',
		'notarial_deed',
		'npwp',
		'siop',
		'bank_account',
		'name_account',
		'account_number',
		array(
		    'label'=>'Buku Rekening',
		    'type'=>'raw',
		    'value'=>CHtml::link('view', '#', array('onclick'=>'$("#bukuRekening").dialog("open"); return false;',))),
		//'picture',
	),
)); ?>

<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id'=>'bukuRekening',
    'options'=>array(
        'title'=>'Buku Rekening',
        'width'=>500,
        'height'=>300,
        'autoOpen'=>false,
    ),
));
    echo CHtml::image(Yii::app()->request->baseUrl . '/images/accountPicture/' . CHtml::encode($model->picture), CHtml::encode($model->picture)
,array('height'=>'100%', 'width'=>'100%'));
$this->endWidget('zii.widgets.jui.CJuiDialog');



?>
//this cgridview to show all of the children that live in model above and their status 1
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'child-data-grid',
	'dataProvider'=>$model->findAnak($model->id),
	'filter'=>$model,
	'columns'=>array(
		'id',
		'child_code',
		'child_name',
		'gender_id',
		'pob',
		'dob',
		array(
			'class'=>'CButtonColumn',
		),
	),
)); ?>

and in model i try to put
public function relations()
	{
		
		return array(
		    
		    'childData'=>array(self::HAS_MANY,'ChildData','lksa_data_id'),
		);
	}
public function findAnak($id)
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		 $criteria->condition = "t.id = childData.lksa_data_id and t.id = ".$id;
		//$criteria->compare('childData.id',$id,true);
		//$criteria->addCondition('regency_id=:userReg');
		//$criteria->params = array(':id'=>$id);
		$criteria->with=array('childData');
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

and i got this error
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'childData.lksa_data_id' in 'where clause'. The SQL statement executed was: SELECT `t`.`id` AS `t0_c0`, `t`.`year` AS `t0_c1`, `t`.`lksa_code` AS `t0_c2`, `t`.`lksa_name` AS `t0_c3`, `t`.`address` AS `t0_c4`, `t`.`regency_id` AS `t0_c5`, `t`.`email` AS `t0_c6`, `t`.`leader` AS `t0_c7`, `t`.`ownership_status_id` AS `t0_c8`, `t`.`contact_person` AS `t0_c9`, `t`.`handphone_number` AS `t0_c10`, `t`.`notarial_deed` AS `t0_c11`, `t`.`npwp` AS `t0_c12`, `t`.`siop` AS `t0_c13`, `t`.`bank_account` AS `t0_c14`, `t`.`name_account` AS `t0_c15`, `t`.`account_number` AS `t0_c16`, `t`.`picture` AS `t0_c17` FROM `lksa_data` `t` WHERE (t.id = childData.lksa_data_id and t.id = 1) LIMIT 10 


can you give me solution?please
0

#2 User is offline   kokomo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 289
  • Joined: 23-July 10

Posted 17 November 2011 - 01:57 PM

I'm not sure but it could be that the same name of the relation and your table childData could cause the problem.

Try to rename the relation.
0

#3 User is offline   angela88 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 144
  • Joined: 14-October 11
  • Location:Jakarta

Posted 18 November 2011 - 02:05 AM

$criteria->condition = "t.id = childData.lksa_data_id and t.id = ".$id;

change to
 $criteria->condition = "t.id = ".$id;


if use "with" it's no need to compare id from 2 table..
cmiiw
sorry :rolleyes: i know it's from me...

and u don't have field lksa_data_id in table childdata..
maybe it's lksadata_id or lksa_id...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users