I haven't run into a query yet where a simple foreach loop did not suffice;
are you doing something similar like this in your views?:

<?php foreach($books as $book): ?>
  <div class="book">
    <h4><?php echo $html->link($book['Book']['title'],
"view/{$book['Book']['id']}"); ?></h4>
    <p><?php echo $book['Book']['short_description'] ?></p>
  </div>
<?php endforeach; ?>

where my controller did:

set('books', $this->Book->findAll());

That's not too bad is it?


the_woodsman wrote:
> 
> 
> Hi Bakers,
> 
> I think there's something I'm not getting about the mechanism for
> passing data in to the view, because my attempts quickly become very
> hard to read.
> 
> I'm frequently passing data from multiple Models and aggregate
> functions into my views.
> However, the format returned from Cake's query functions can't easily
> be traversed to render the page, so needs its structure changed in the
> Controller to be more usable by the View.
> 
> However, with more complex pages, converting these multi dimensional
> arrays I get from queries into a usable form for a view, then iterating
> through them in the views, makes for highly unreadable and hard to
> maintain code.
> 
> What solutions have people come up with to avoid such tricky multi
> dimensional arrays?
> 
> I'm considering passing Objects to my view, however that means I have
> to create classes/interfaces to define the objects I'm going to pass to
> the view, or create objects on the fly, including their members and
> methods, which doesn't look fun.
> 
> Someone must have surely seen this as a problem before, and found a
> nice way to deal with it?
> 
> Or is there just something I'm missing?
> 
> Help!!!!!!!
> 
> 
> > 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Passing-data-to-the-view-in-a-nice-way--tf2780224.html#a7757358
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to