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

  • Home
  • SEARCH
  • 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 8683617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:05:39+00:00 2026-06-12T22:05:39+00:00

I have a nested array that is compiled via the model in a CakePHP

  • 0

I have a nested array that is compiled via the model in a CakePHP request. The array can be nested at a variable depth, and the content is to be returned to the user.

Currently the looping and rendering process for this array is completed using a function in the View element of the request. This function is first called at the base array’s depth, and repeated for any array element that has further array children. eg.

function print_depth($elements) {
  foreach($elements as $element) {
    echo $element['title'];

    if($element['children']) {
      print_depth($element['children']);
    }
  }
}

print_depth($elements);

With this process, I can print out all levels of the array, whilst still keeping the markup flexibility within the view (hence, it is skinnable), but I imagine this is the incorrect location for the function that handles this.

Is there a more MVC-valid process for this operation?

  • 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-12T22:05:41+00:00Added an answer on June 12, 2026 at 10:05 pm

    Create a helper instead of putting a single function in the view code.

    What you do sounds like rendering a tree, there is already a tree helper out there.

    https://github.com/CakeDC/utils/blob/master/View/Helper/TreeHelper.php

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

Sidebar

Related Questions

I have a nested collection of collection of array that can go to any
I have a generated nested Array which I store some data. How can i
I have a simple structure in mongodb, with nested array. How can I update
PROBLEM I have a nested PHP array that I need to populate from flat
I have a struct that's inside an array that is nested inside another struct,
I have a nested array that looks like this: @nested = [ ['1','2','3'], ['1','5','9'],
I have a large nested array that I'm generating from parsing a CSV file
I have an Array nested withing an Object that's inside an Object which is
I have a method that gets a nested array as parameter: Number[][] data where
I have an nested array and want to remove the entries that matches the

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.