저는 하루 종일이 문제에 직면 해 왔습니다.Yii 프레임 워크 : HAS_MANY, BELONGS_TO의 페이지 매기기
서비스 및 로그 테이블이 2 개 있습니다. 각 서비스는 많은 로그를 가질 수 있으며 각 로그는 서비스에 속합니다. 두 가지 모두에 대해 CRUD 기능을 생성 할 수있었습니다./
응용 프로그램/모델
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view', array
(
'model' => $this->loadModel($id),
));
}
Log.php
/**
* @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
(
'services' => array(self::BELONGS_TO, 'Service', 'sv_ident_nr'),
);
}
응용 프로그램/모델/Service.php
/**
* @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
(
'logs' => array(self::HAS_MANY, 'Log', 'sv_ident_nr'),
);
}
응용 프로그램/controlelrs/ServiceController.php
: 여기 는 내가 가진 무엇app/views/service/view.php
<h1>Service: <?php echo $model->ident_nr; ?></h1>
<table class="dataGrid">
<tr>
<th class="label"><?php echo CHtml::encode($model->getAttributeLabel('proj_nr')); ?></th>
<td><?php echo CHtml::encode($model->proj_nr); ?></td>
</tr>
<tr>
<th class="label"><?php echo CHtml::encode($model->getAttributeLabel('customer')); ?></th>
<td><?php echo CHtml::encode($model->customer); ?></td>
</tr>
<h1>Comments</h1>
<?php foreach ($model->logs as $log): ?>
<div class="comment" id="c<?php echo $log->id; ?>">
<div class="actions">
<?php
echo CHtml::link('View',array($this->createUrl('../log/view', array('id'=>$log['id']))));
echo(' ');
echo CHtml::link('Update',array($this->createUrl('../log/update', array('id'=>$log['id']))));
echo(' ');
echo CHtml::link('Delete',array($this->createUrl('../log/delete', array('id'=>$log['id']))));
?>
</div>
<div class="author">
<?php
echo $log->logger;
?>
</div>
<div class="time">
<?php echo date('j F Y \a\t h:i a', $log->created_at); ?>
</div>
<div class="content">
<?php echo nl2br(CHtml::encode($log->comment)); ?>
</div>
</div><!-- comment -->
<?php endforeach; ?>
질문 : 나는 'foreach 루프'에서 결과를 paginating에 대해 어떻게 가야합니까? 감사합니다.
당신은 cgridview – Orlymee
을 사용할 수 있습니다. 정확히 사용하지 않으려는 것입니다. – Madi
다음을보십시오 : http://www.yiiframework.com/doc/api /1.1/CPagination – Orlymee