2012-07-10 4 views
0

저는 하루 종일이 문제에 직면 해 왔습니다.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('&nbsp'); 
      echo CHtml::link('Update',array($this->createUrl('../log/update', array('id'=>$log['id'])))); 
      echo('&nbsp'); 
      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에 대해 어떻게 가야합니까? 감사합니다.

+0

당신은 cgridview – Orlymee

+0

을 사용할 수 있습니다. 정확히 사용하지 않으려는 것입니다. – Madi

+0

다음을보십시오 : http://www.yiiframework.com/doc/api /1.1/CPagination – Orlymee

답변

0

docs for CListView 봐. 페이징, Ajax 검색 등을 할 수 있으며 데이터에 대한 고유 한 템플리트를 사용합니다. 시간이 충분합니다 ...

+0

대단히 감사합니다. 너는 내 하루를 구했다. 그게 바로 제가 찾고 있던 것입니다. 당신이 문서를 통해 날아가는 경우에 아주 좋은 세부 사항을 간과하는 것은 아주 쉽습니다. – Madi

0

내가 이전에 토론 한 내용을 바탕으로 이전에 생각한 것 같습니다. 대신 CGridView의

Yii Simple Pagination

+0

도움 주셔서 감사합니다. 그러나 액세스하려고 할 때 "비 객체의 속성을 얻으려고합니다."라는 메시지가 나타납니다. breadcrumbs = array ( 'Service'=> 배열 ('index'), $ model-> ident_nr, ); – Madi