Answer the question
In order to leave comments, you need to log in
Yii1.1. How to display data from linked table in CListView?
Yii1.1. How to display data from linked table in CListView?
Action code:
public function actionIndex()
{
$firsts = Firsts::model()->with('seconds')->findByPk(1);
$firstss = Firsts::model()->with('seconds')->findAll();
foreach ($firstss as $second)
echo $second->name. "<br>";
$criteria = new CDbCriteria;
// $criteria->condition = 'id > 2';
// $criteria->order = 'name ASC';
$dataProvider=new CActiveDataProvider('Firsts',array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>9,
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
'firsts'=>$firsts,
'firstss'=>$firstss,
));
}
<?php
/* @var $this AllController */
/* @var $dataProvider CActiveDataProvider */
?>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
//'emptyText'
'sorterHeader'=>'Сортировать по: ',
'summaryText' => '{start} - {end} из {count}',
'sortableAttributes'=>array('name', 'id', 'lastname'),
));
foreach ($firsts->seconds as $second)
echo $second->name. "<br>";
?>
<?php
/* @var $this FirstsController */
/* @var $data Firsts */
?>
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('name')); ?>:</b>
<?php echo CHtml::encode($data->name); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('lastname')); ?>:</b>
<?php echo CHtml::encode($data->lastname); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('phone')); ?>:</b>
<?php echo CHtml::encode($data->phone); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('sd')); ?>:</b>
<?php echo CHtml::encode($data->seconds->name); ?>
<br />
</div>
<?php
// foreach ($firsts->seconds as $second)
// echo $second->name. "<br>";
// echo $firsts->seconds->name;
// foreach ($firsts->name as $second)
// echo $second. "<br>";
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question