AD7six.com

Elements and Recursion

3 September, 2006

Show comments

A long time ago, I took to using elements as shown in the paste below.

echo $this->renderElement("Element",$params);

At the time, this was the only way I could find to pass the information from the view in general to the element. If this was needed at all, it was probably a temporary glitch but I kept to this syntax since that time. It is overkill to do this now, and moreover if you use the above you may get sporadic errors like "Warning: array_merge_recursive(): recursion detected in /cake/libs/view/view.php on line 406".

The way to avoid such problems is to not do what isn't necessary ;)

// If the view already contains everything of 

interest to the Element there is no need to pass any params
echo $this->renderElement("Element");
// If there is some need 

to pass extra parameters, pass just the parameters of interest
echo 

$this->renderElement("Element",array("extra"=>$parameter));

I hope the time I spent trying to figure this out is saved for others :)