0

私は一日中この問題に直面しています。

ServiceとLogの2つのテーブルがあります。各サービスは多くのログを持つことができ、各ログはサービスに属します。両方のCRUD機能を生成することができました。これが私が得たものです:

app / models / 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'),
    );
}

app / models / 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'),
    );
}

app / controlelrs / ServiceController.php

/**
 * 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),
    ));
}

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ループ」で結果をページ付けするにはどうすればよいですか?ありがとう

4

2 に答える 2

0

CGridViewの代わりに、CListViewのドキュメントを参照してください。これにより、データに独自のテンプレートを使用しながら、ページング、Ajax検索などを実行できます。それはあなたの時間の価値があります...

于 2012-07-11T04:07:01.820 に答える
0

以前のあなたとの話し合いに基づいて、これがあなたが求めているものだと思います。

Yiiの単純なページ付け

于 2012-07-10T16:24:01.823 に答える