How can i call an element in cakePHP?
i need to call a cakePHP element in an Ajax function; when the user clicks an item want to populate a DIV with the content of an element. The problem is that i don't know how to properly create that element because i call the url but cakephp renders all the webpage instead of only the element. How can i call only the element throu开发者_运维百科gh a controller action?
Thanks in advance c.
Try calling an action, but within it, specify:
$this->layout = false;
That makes it so it does not use a layout file.
Then, within the view of that action, just echo the element - nothing else:
<?php
echo $this->element('myElement');
?>
faster way: $this->render('/elements/myElement','ajax');
at the end of your controller action.
$this->layout = NULL;
$this->autoRender = false;
// your code
$this->render('/elements/myElement');
精彩评论