Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8212313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:42:48+00:00 2026-06-07T10:42:48+00:00

I have been facing this problem all day long. I have 2 tables Service

  • 0

I have been facing this problem all day long.

I have 2 tables Service and Log. Each Service can have many Logs and each Log belongs to a Service.
I managed to generate the CRUD functionality for both.
Here is what I got:

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; ?>

The question is : How do I go about paginating the results in the ‘foreach loop’?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:42:50+00:00Added an answer on June 7, 2026 at 10:42 am

    Instead of a CGridView, look at the docs for CListView. It allows you to do paging, Ajax retrieval, etc while also using your own template for the data. It’s well worth your time …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hell All, So I have been facing this behavior for quite some time and
I have been facing a strange problem while returning dataset through WCF service (WSHttpBinding).
This is a problem I have been trying to track down for a couple
It's been now 1 week that I am facing this problem. I'm trying to
Context: An ongoing problem we have been facing is unit testing our market data
So, I have been facing a problem with using subprocess for a python app
Here is the problem I am facing. I have been tasked with testing the
I have been facing a problem in InstallScript to get the list of registry
I have been facing a real strange problem. I have installed and used android
We have been facing Out of Memory errors in our App server for sometime.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.