Re: Using $this->set in view doesn't set the var

2011-09-13 Thread Xoubaman
I will suggest the correction to the documentation.

Thanks for the answers!

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-13 Thread Xoubaman
I'm talking to correct this sentence (from 
http://book.cakephp.org/view/1086/set):

In your view file you can do
$this->set('activeMenuButton', 'posts');

*Then in your layout the $activeMenuButton variable will be available and 
contain the value 'posts'.*

because it should say that the var will be available through 
$this->viewVars, not as a local variable. That's why I'm confused, I never 
really thought if it was possible or not.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-13 Thread mark_story
It totally does, it does not however, come with a time-machine.  Once
you understand the constraints of time and space, and the fact that
you cannot inject local variables into a different execution stack
frame in PHP it works exactly the same.  Having to update the cake
docs about these constraints seems a bit condescending to me.

-Mark

On Sep 13, 6:36 am, Xoubaman  wrote:
> I think doc needs a correction then, as Var::set doesn't work exactly
> analogous to Controller::set.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-13 Thread mark_story


On Sep 13, 11:54 am, gremlin  wrote:
> Keep in mind - when you are doing $this->set from an element: You
> aren't calling View::set - you are calling Element::set. Why would you
> expect that to behave as if it was an instance of the View class when
> it isn't? Also, the two pass rendering of CakePHP means that in order
> for what you propose to work you would need a 3rd pass through the
> stack of set variables and rendered elements before parsing the
> combined view output. This isn't how Cake works and struggling this
> much to force the framework to do something it isn't meant to is going
> to simply be a waste of your time, either now - getting it to work -
> or later when you have to support it.
>

Element::set is not a function in CakePHP, so I don't know why you
think it exists.  Elements execute in the context of the view.  So
their $this is the same as the $this in the view and layout.

-Mark

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-13 Thread gremlin
Keep in mind - when you are doing $this->set from an element: You
aren't calling View::set - you are calling Element::set. Why would you
expect that to behave as if it was an instance of the View class when
it isn't? Also, the two pass rendering of CakePHP means that in order
for what you propose to work you would need a 3rd pass through the
stack of set variables and rendered elements before parsing the
combined view output. This isn't how Cake works and struggling this
much to force the framework to do something it isn't meant to is going
to simply be a waste of your time, either now - getting it to work -
or later when you have to support it.

On Sep 13, 6:36 am, Xoubaman  wrote:
> I think doc needs a correction then, as Var::set doesn't work exactly
> analogous to Controller::set.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-13 Thread Xoubaman
I think doc needs a correction then, as Var::set doesn't work exactly 
analogous to Controller::set.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-12 Thread mark_story
Yeah you can't use set() to magically push a variable into the layout
scope from an element.  That's simply impossible in PHP.  If you have
an element in your layout that uses View::set()  you should either get
it from $this->viewVars or use $this->getVar().  To access it later in
the layout.

-Mark

On Sep 10, 3:37 am, WebbedIT  wrote:
> Yip, the api does state "Allows a template or element to set a
> variable that will be available in a layout or other element", but
> maybe this is when the element is being called from the view not the
> layout?
>
> People are not really supposed to read your layout though, that is set
> and should rarely be changed. Plus it's a lot cleaner to only be
> echoing $content_for_layout, $menu_for_layout etc. than it is to be
> calling all view data from the layout.
>
> However, I am not experienced enough with MVC to give a compelling
> argument against it, I just know when something rubs against Cake's
> conventions then it;s normally not a good idea.
>
> HTH, Paul.
>
> On Sep 9, 9:18 pm, Xoubaman  wrote:
>
>
>
>
>
>
>
> >http://api13.cakephp.org/class/view#method-Viewsethttp://book.cakephp...
>
> > Someone of the core team answered that Var::set could be used to solve a
> > similar issue in a post I here found when searching to my question. Don't
> > remember the search subject now :(
>
> > I mean cleaner in the sense of it's more readable one layout with some echo
> > $var that another one with some echo $this->element(name, params stuff),
> > almost in the application I'm developing. Maybe it's not the most elegant
> > way, but, if we should not set vars in the views, why is still a method to
> > do it?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-10 Thread WebbedIT
Yip, the api does state "Allows a template or element to set a
variable that will be available in a layout or other element", but
maybe this is when the element is being called from the view not the
layout?

People are not really supposed to read your layout though, that is set
and should rarely be changed. Plus it's a lot cleaner to only be
echoing $content_for_layout, $menu_for_layout etc. than it is to be
calling all view data from the layout.

However, I am not experienced enough with MVC to give a compelling
argument against it, I just know when something rubs against Cake's
conventions then it;s normally not a good idea.

HTH, Paul.

On Sep 9, 9:18 pm, Xoubaman  wrote:
> http://api13.cakephp.org/class/view#method-Viewsethttp://book.cakephp.org/view/1086/set
>
> Someone of the core team answered that Var::set could be used to solve a
> similar issue in a post I here found when searching to my question. Don't
> remember the search subject now :(
>
> I mean cleaner in the sense of it's more readable one layout with some echo
> $var that another one with some echo $this->element(name, params stuff),
> almost in the application I'm developing. Maybe it's not the most elegant
> way, but, if we should not set vars in the views, why is still a method to
> do it?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-09 Thread Xoubaman
http://api13.cakephp.org/class/view#method-Viewset
http://book.cakephp.org/view/1086/set

Someone of the core team answered that Var::set could be used to solve a 
similar issue in a post I here found when searching to my question. Don't 
remember the search subject now :(

I mean cleaner in the sense of it's more readable one layout with some echo 
$var that another one with some echo $this->element(name, params stuff), 
almost in the application I'm developing. Maybe it's not the most elegant 
way, but, if we should not set vars in the views, why is still a method to 
do it?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-08 Thread WebbedIT
Can you show me the documentation that says you can set variables from
an element to be used in the layout?

If something is wrongly documented the core team will gladly correct
it, but remember an element is not a view ... whilst closely related
to views, an element is not meant to interact with the layout.

What may seem a simpler approach to you does not neccessarily equal a
cleaner approach.  You're changing the request and response process
from:

- Controller (recieves request)
- Model (requests and processes relevant data)
- Controller (passes data to view)
- View (constructs view - should be doing minimal data processing)
- View elements (passing data sent from model to view)
- Layout (builds layout around view - should be doing even less data
processing than view)
- Layout elements (passing data sent from view to layout)

to:

- Controller (recieves request)
- Model (requests and processes relevant data)
- Controller (passes data to view)
- View (bypass, as not building view)
- View elements (bypass, as not building view)
- Layout (builds layout around nothing as no view passed)
- Loader elements (now you request and try to display all your data)

Essentially, you are using elements in a non-conventional manner, then
saying the documentation is wrong!

HTH, Paul
@phpMagpie

On Sep 7, 4:03 pm, Xoubaman  wrote:
> I know it's possible to accomplish it like you said -and thanks for your
> answers and efforts to help, by the way-, but the basis of my question is
> why a documented view method it's not working as expected.
>
> I was trying my approach because I think it would be simplier and cleaner,
> to an unexperienced Cake user, edit or create layouts if he only have to
> echo a var instead an element with passed params.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-07 Thread Xoubaman
I know it's possible to accomplish it like you said -and thanks for your 
answers and efforts to help, by the way-, but the basis of my question is 
why a documented view method it's not working as expected.

I was trying my approach because I think it would be simplier and cleaner, 
to an unexperienced Cake user, edit or create layouts if he only have to 
echo a var instead an element with passed params.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-07 Thread WebbedIT
So you're wanting to pass a fully rendered element to the layout as a
variable?  Much in the same way we pass a fully rendered view to the
layout as $content_for_layout.

When building dynamic sidebars I created an array in the controller,
including the data and element name for each position in the sideber,
which I loop through in the view calling $this->element($element,
$dataArray());

You could do the same or if you must have things in the layout then
you would need to pass the array from the view to the layout and look
through it there calling the elements.

Either way the data is already available at the view and/or layout as
it is from there you call $this->element() and pass it the data.

HTH, Paul.

On Sep 6, 11:26 am, Xoubaman  wrote:
> My concrete case:
>
> In a CMS-like app, I have modules that can be attached to layout positions.
> Layout positions are vars echoed in each layout. So, I use a loader element,
> placed at the top of each layout, that should load each position var with
> his own output.
>
> Layout example:
>
> 
> elements('loader'); ?>
> 
> 
> ...
> 
> ...
> 
> ...
> 
>
> Loader behavior:
>
> foreach ($modules as $position => $attached_modules) {
> foreach ($attached_modules as $model) {
>  $output[$positions] .= $this->element($model);
>
> }
>
> $this->set($output);
>
> }
>
> Something like that. Code is not that way exactly, but I think it's enough
> to get the idea. The problem is that the $this->set at the bottom of loader
> element sets the var in viewVars attribute, but doesn't populate the vars to
> be accessed straight in the layout (as said in the doc, 
> here:http://book.cakephp.org/view/1086/set)
>
> I know I could call each element in each position, but it will mess up the
> layout code and difficult creating or editing layouts, instead the elegant
> echo $position ^^

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-06 Thread Xoubaman
My concrete case:

In a CMS-like app, I have modules that can be attached to layout positions. 
Layout positions are vars echoed in each layout. So, I use a loader element, 
placed at the top of each layout, that should load each position var with 
his own output.

Layout example:


elements('loader'); ?>


...

...

...


Loader behavior:

foreach ($modules as $position => $attached_modules) {
foreach ($attached_modules as $model) {
 $output[$positions] .= $this->element($model);
}

$this->set($output);
}

Something like that. Code is not that way exactly, but I think it's enough 
to get the idea. The problem is that the $this->set at the bottom of loader 
element sets the var in viewVars attribute, but doesn't populate the vars to 
be accessed straight in the layout (as said in the doc, here: 
http://book.cakephp.org/view/1086/set)

I know I could call each element in each position, but it will mess up the 
layout code and difficult creating or editing layouts, instead the elegant 
echo $position ^^

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-06 Thread WebbedIT
Still don't get it, maybe you need to show us your real world example
of how the element is communicating with the layout and other
elements.  That way we can understand and someone can solve or offer
an alternative solution.

At the initial page load, all elements should have their data passed
to them via the main controller action or their own requestAction, I
would fire separate ajax requests for other elements if they are to be
updated due to a DOM change.

I'm not sure the documentation does specifically say that elements can
set vars, did you read that from here?
http://book.cakephp.org/view/1081/Elements

You can set variables from the controller (to the view) and the view
(to the layout) but elements are not supposed to go to anything else,
they are the end of the line.

HTH, Paul
@phpMagpie

On Sep 5, 11:37 am, Xoubaman  wrote:
> Me neither, until now :)
>
> On the topic of setting vars in an element, regardless of it being wrong or
> not, the point is that it's possible. At least the doc says so, but it's not
> working for me (the Var::set() method).
>
> You may have an element that gets data from requestAction and, depending on
> the returned values, subsecuent layout contents will need different vars
> defined.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-05 Thread Xoubaman
Me neither, until now :)

On the topic of setting vars in an element, regardless of it being wrong or 
not, the point is that it's possible. At least the doc says so, but it's not 
working for me (the Var::set() method).

You may have an element that gets data from requestAction and, depending on 
the returned values, subsecuent layout contents will need different vars 
defined.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using $this->set in view doesn't set the var

2011-09-05 Thread WebbedIT
I have never accessed anything from $this->viewVars, once set a
variable is accessed from $variableName.

Something sounds wrong with your methodology If you're setting
variables in an element to be used in other elements/parts of the
layout.  An element by definition is a contained collection of view
code, not sure why it should interact during a page load with other
elements.

HTH, Paul
@phpMagpie

On Sep 1, 6:20 pm, Xoubaman  wrote:
> I have an element in layout that generates some variables I want to use
> following parts of layout and view. As read in doc
> (http://book.cakephp.org/view/1086/set), using $this->set('varname', $value)
> will result in $varname available in the layout, but I'm getting a Undefined
> variable notice.
>
> debug($this->viewVars) before the var-generating element throws something
> like:
>
> Array
> (
>     [title_for_layout] => Awesome web
>     [controller_set_var1] => lol
>     [controller_set_var2] => foo
> )
>
> Then, the element is echoed, and debugging $this->viewVars shows:
>
> Array
> (
>     [title_for_layout] => Awesome web
>     [controller_set_var1] => lol
>     [controller_set_var1] => lol
>     [element_set_var] => gotcha!
> )
> But $element_set_var stills undefined.
>
> Is this the normal behavior? Should I take $element_set_var manually from 
> $this->viewVars?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Using $this->set in view doesn't set the var

2011-09-01 Thread Xoubaman
I have an element in layout that generates some variables I want to use 
following parts of layout and view. As read in doc 
(http://book.cakephp.org/view/1086/set), using $this->set('varname', $value) 
will result in $varname available in the layout, but I'm getting a Undefined 
variable notice.

debug($this->viewVars) before the var-generating element throws something 
like:

Array
(
[title_for_layout] => Awesome web
[controller_set_var1] => lol
[controller_set_var2] => foo
)

Then, the element is echoed, and debugging $this->viewVars shows:

Array
(
[title_for_layout] => Awesome web
[controller_set_var1] => lol
[controller_set_var1] => lol
[element_set_var] => gotcha!
)
But $element_set_var stills undefined.

Is this the normal behavior? Should I take $element_set_var manually from 
$this->viewVars?


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php