php - Yii - How To Show Other Property Not Its ID -
i have related tables on database picture below:
then, have page view file picture below:
i want show username, not it's id. here code in view/file/_view.php
<div class="view"> <b><?php echo chtml::encode($data->getattributelabel('id_file')); ?>:</b> <?php echo chtml::link(chtml::encode($data->id_file),array('view','id'=>$data->id_file)); ?> <br /> <b><?php echo chtml::encode($data->getattributelabel('nama_file')); ?>:</b> <?php echo chtml::encode($data->nama_file); ?> <br /> <b><?php echo chtml::encode($data->getattributelabel('deskripsi')); ?>:</b> <?php echo chtml::encode($data->deskripsi); ?> <br /> <b><?php echo chtml::encode($data->getattributelabel('id_user')); ?>:</b> <?php echo chtml::encode($data->id_user); ?> <br /> <b><?php echo chtml::encode($data->getattributelabel('id_kategori')); ?>:</b> <?php echo chtml::encode($data->id_kategori); ?> <br /> <b><?php echo chtml::encode($data->getattributelabel('tgl_post')); ?>:</b> <?php echo chtml::encode($data->tgl_post); ?> <br /> <hr /> </div>
filecontroller.php
public function actionview($id) { $this->render('view',array( 'model'=>$this->loadmodel($id), )); }
index.php output _view.php
<?php $this->breadcrumbs=array( 'files', ); ?> <h1>files</h1> <?php $this->widget('bootstrap.widgets.tblistview',array( 'dataprovider'=>$dataprovider, 'itemview'=>'_view', )); ?>
can me change it? lot. p.s.: sorry bad english
first need have relation user table in model, assume have since have fks on pic above. lets assume relation "user" , in user table field want display "username".
you should replace: php <?php echo chtml::encode($data->id_user); ?>
with: php <?php echo chtml::encode($data->user->username); ?>
Comments
Post a Comment