thoughts about elements
Hi everyone, I have been thinking a bit about how elements work and how to best make use of them. My starting-point is that I really don't like having to set a variable in the controller to get it to the view and then have to also pass it along to the element. This somehow feels redundant to me and I have been pondering the alternatives and which to favor. Is there any special reason why elements do not get access to variables set in the view? Or is it just a result of how php handles scope? There is an exception. $this-data This little variable is automatically brought along to the view (and any models) and is also accessible from inside elements (and helpers?). This variable looks like a good candidate for passing data. I can set a key in data instead of setting a variable using set. The problem with using data is that it is intended for storing form-data / model-data, right? In some cases an element can call $this-requestAction() to get some data for itself. This will not cover request-specific data such as an id. Imagine a common element for generating a list of available articles. The element needs a list of articles (can use requestAction) and knowledge of the currently selected article which must still be passed from the controller so the element can not be self- sufficient. What I want is a setup where I only need to set my view-data once for my view and any elements. This is mostly since passing them further makes the code ugly and boring to update each call to an element with a new variable when the element is expanded or altered. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: thoughts about elements
On Jan 18, 9:43 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi everyone, I have been thinking a bit about how elements work and how to best make use of them. My starting-point is that I really don't like having to set a variable in the controller to get it to the view and then have to also pass it along to the element. This somehow feels redundant to me and I have been pondering the alternatives and which to favor. Is there any special reason why elements do not get access to variables set in the view? They do already see: https://trac.cakephp.org/browser/branches/1.2.x.x/cake/libs/view/view.php?rev=6387#L400 hth, AD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: thoughts about elements
I hadn't noticed. I had only checked view-element not controller- element. Thanks for the tip, Andy. On Jan 18, 10:04 am, AD7six [EMAIL PROTECTED] wrote: On Jan 18, 9:43 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi everyone, I have been thinking a bit about how elements work and how to best make use of them. My starting-point is that I really don't like having to set a variable in the controller to get it to the view and then have to also pass it along to the element. This somehow feels redundant to me and I have been pondering the alternatives and which to favor. Is there any special reason why elements do not get access to variables set in the view? They do already see:https://trac.cakephp.org/browser/branches/1.2.x.x/cake/libs/view/view... hth, AD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---