Reputation: 179
I'm working with CakePHP 1.3. I'm making an AJAX call where I want the server to return some HTML that corresponds to several of rows of results that I can throw inside a <div>
. I have the template for a single row stored as an element called 'library_track'. The element requires variables 'id', 'artist' and 'name' to be passed to it. I would like my function getResults()
to return a block of HTML that is composed of HTML from several elements.
Can anyone show me what this code would look like please?
Upvotes: 0
Views: 1949
Reputation: 522125
Just as usual, you'll probably have to loop through the results in your view:
Controller:
function getResults() {
// here be dragons
$this->set(compact('results'));
}
View /foo/getresults.ctp:
foreach ($results as $result) {
echo $this->element('library_track', array('id' => $result['Result']['id'], ...));
}
Upvotes: 1