user606521
user606521

Reputation: 15474

element is rendered without layout

I have books/index controller and view. The view looks like this:

abcdef
123445
<?php echo $this->element('categorytree'); ?>
xyz
999

I have elements/categorytree element:

<?php
    function my_function() { echo '123'; } 
    echo 'element is here!';
?>

And when I go to books/index in my browser, the element is rendered without layout so source output is:

abcdef
123445
element is here!
xyz
999

And when I remove function declaration in element the problem disappears - the whole layout is rendered - so the problem is when I declare any php function inside element, then if this element is "fetched" by any view only this element is rendered without a layout.

This problem appeared suddenly, I don;t know why... Before I used functions declared in element and didnt have any problem...

------------------ solved

Wow this is strange - the problem was caused by the <!-- --> tags after the $this->element()...

Upvotes: 1

Views: 694

Answers (1)

dr Hannibal Lecter
dr Hannibal Lecter

Reputation: 6721

Although you've found the solution to your problem, I'd just like to point out that defining functions in your view is a horrible practise. A better and cleaner way to do it is to create a custom helper, and simply use that.

A view is simply not the place to write functions or classes.

Upvotes: 2

Related Questions