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 7413877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:58:13+00:00 2026-05-29T06:58:13+00:00

I have a model Tasklist, and each Tasklist item belongs to a Service item.

  • 0

I have a model Tasklist, and each Tasklist item belongs to a Service item.

In my Tasklist controller:

function index() {
  $this->Tasklist->recursive = 0;
  $this->set('tasklists', $this->Tasklist->find('all', array(
    'order' => array(
      'Service.name' => 'ASC',
      'Tasklist.name' => 'ASC'
    )
  )));
}

Relevant part of my simple index View:

<?php foreach ($tasklists as $tasklist): ?>
    <tr>
      <td><?php echo $tasklist['Tasklist']['id']; ?></td>
      <td><?php echo $tasklist['Tasklist']['name']; ?></td>
      <td>
      <?php echo $this->Html->link($tasklist['Service']['name'], array('controller' => 'services', 'action' => 'view', $tasklist['Service']['id'])); ?>
      </td>
      <td><?php echo $tasklist['Tasklist']['created']; ?></td>
      <td><?php echo $tasklist['Tasklist']['modified']; ?></td>
      <td>
      <?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $tasklist['Tasklist']['id']), array('class' => 'button edit')); ?>
      </td>
    </tr>
<?php endforeach; ?>

Instead of printing the Service name in every table row I would like to print it as a with the Tasklists grouped beneath each one:

<tr>
      <th colspan="5"><?php echo $this->Html->link($tasklist['Service']['name'], array('controller' => 'services', 'action' => 'view', $tasklist['Service']['id'])); ?></th>
</tr>
<tr>
      <td><?php echo $tasklist['Tasklist']['id']; ?></td>
      <td><?php echo $tasklist['Tasklist']['name']; ?></td>
      <td><?php echo $tasklist['Tasklist']['created']; ?></td>
      <td><?php echo $tasklist['Tasklist']['modified']; ?></td>
      <td>
      <?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $tasklist['Tasklist']['id']), array('class' => 'button edit')); ?>
      </td>
</tr>

I have experimented with using the group parameter in my controller and a nested foreach in my view, but cannot get it to work.

  • 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-05-29T06:58:13+00:00Added an answer on May 29, 2026 at 6:58 am

    I’d do it like this

       $current_service = '';
        <?php foreach ($tasklists as $tasklist): ?>
        <?php if($current_service != $tasklist['Service']['name']): ?>
        <tr>
              <th colspan="5"><?php echo $this->Html->link($tasklist['Service']['name'], array('controller' => 'services', 'action' => 'view', $tasklist['Service']['id'])); ?></th>
        </tr>
        <?php $current_service = $tasklist['Service']['name']; ?>
        <?php endif; ?>
        <tr>
              <td><?php echo $tasklist['Tasklist']['id']; ?></td>
              <td><?php echo $tasklist['Tasklist']['name']; ?></td>
              <td><?php echo $tasklist['Tasklist']['created']; ?></td>
              <td><?php echo $tasklist['Tasklist']['modified']; ?></td>
              <td>
              <?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $tasklist['Tasklist']['id']), array('class' => 'button edit')); ?>
              </td>
        </tr>
    
        <?php endforeach; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model Products with columns: name, number, description Index defined for this model
I have model like this: scope :search_posts, lambda { |query| mega_posts.where( title LIKE ?
Lets say I have model inheritance set up in the way defined below. class
In my controller I have model operations that can return empty results. I've setup
I have model with a Foreign Key to itself like this: class Concept(models.Model): name
I have model public class MyModel { public string Name { get; set;} }
I have: 1) public class Model { public String Name { get; set; }
I have model: [Validator(typeof(RegisterValidator))] public class RegisterModel { public string Name { get; set;
I have model represent association rule (Body => Head) def Item has_many :heads has_many
I have model like this: class Kaart(models.Model): name = models.CharField(max_length=200, verbose_name=Kaardi peakiri, help_text=Sisesta kaardi

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.