In my books view.ctp, I want to have a list of 5 books that are
related via the genres data, which has a HABTM relationship. Although
I can do this by placing a function similar() in the
genres_controller, I have to call it from the view with requestAction.

// genres_controller.php
  function similar($id = null) {
    $similarbooks = $this->Genre->Book->find('all', array(
      'contain' => array(
        'Author' => array('fields' => array('id', 'slug')),
      ),
      'fields' => array('id', 'slug', 'title'),
      'limit' => 5,
      'order' => 'RAND()',
    ));
    $this->set(compact('similarbooks'));
  }

// Book view.ctp
  $results = $this->requestAction('/genres/similar/' . $id);

Of course I don't want to really use requestAction (the only place so
far I have used it!) but I would also like to be able to bring up 5
random books from ALL the genres the book is assigned to - at the
moment I am just searching on one genre id.

I also know that this approach is not very good if I wish to include 5
books which are related to say, both Genre and Author.

At some point down the line I would also like to include a "5 Related
Authors" list, so I guess I need a more modular approach (would
elements be it?) - the problem is that I am completely stumped, even
after a week looking at this!

The solution I currently have is better than nothing, but I would be
very grateful if anyone has an idea on how I could achieve a proper
solution.

Many thanks, Mike.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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