Re: Passing arguments to a nested element

2007-04-21 Thread Gonzalo Servat
On 4/22/07, Mariano Iglesias <[EMAIL PROTECTED]> wrote:
>
>
> You are right, view vars will be passed along to elements, but he was
> asking
> about vars directly passed from the view to the element. Otherwise you are
> right, and there's no more he has to do than simply use the view variable.


I guess that's another work around. Instead of passing arguments to the
element, I could use $this->set() ...

- Gonzalo

--~--~-~--~~~---~--~~
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: Passing arguments to a nested element

2007-04-21 Thread Mariano Iglesias

You are right, view vars will be passed along to elements, but he was asking
about vars directly passed from the view to the element. Otherwise you are
right, and there's no more he has to do than simply use the view variable.

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar


-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de dericknwq
Enviado el: Domingo, 22 de Abril de 2007 01:27 a.m.
Para: Cake PHP
Asunto: Re: Passing arguments to a nested element

If I'm not wrong, your viewVars are always passed to the element. So
in fact once you've set the vars using $this->set() on your
controller, all the elements could receive those variables as well
even if you don't specifically provide the params when calling
renderElement.


--~--~-~--~~~---~--~~
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: Passing arguments to a nested element

2007-04-21 Thread dericknwq

If I'm not wrong, your viewVars are always passed to the element. So
in fact once you've set the vars using $this->set() on your
controller, all the elements could receive those variables as well
even if you don't specifically provide the params when calling
renderElement.

That said, I may have misunderstood your question. :p

On Apr 22, 10:03 am, Gonza <[EMAIL PROTECTED]> wrote:
> Hi Mariano,
>
> Gracias. Like you said, it's not the most elegant solution but it'll
> probably work.
>
> Thanks!
> Gonzalo
>
> On Apr 21, 8:55 pm, "Mariano Iglesias" <[EMAIL PROTECTED]>
> wrote:
>
> > You can do it through a quick hack, though it is not very elegant. Let's say
> > that on your view you have:
>
> > renderElement('element1', array('arg1' => 'Hello', 'arg2'
> > => 'World')); ?>
>
> > And element1 includes element2. Element2 looks like:
>
> > 
>
> > Then the hack is to make element1 look like:
>
> > 
> > $loaded = am(array_keys($this->viewVars), array_keys($this->loaded));
> > $args = array_diff_key($___dataForView, array_flip($loaded));
>
> > echo $this->renderElement('element2', $args);
>
> > ?>
>
> > -MI
>
> > ---
>
> > Remember, smart coders answer ten questions for every question they ask.
> > So be smart, be cool, and share your knowledge.
>
> > BAKE ON!
>
> > blog:http://www.MarianoIglesias.com.ar
>
> > 
> > De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
> > de Gonzalo Servat
> > Enviado el: Sábado, 21 de Abril de 2007 08:35 p.m.
> > Para: cake-php@googlegroups.com
> > Asunto: Re: Passing arguments to a nested element
>
> > .. but not quite the solution I was looking for. What I'm trying to avoid is
> > having to specifically write each and every variable in either method. I was
> > hoping for a way to grab them all and send the arguments to the next
> > renderElement call. Maybe I understood how to use compact? I'd really
> > appreciate an example.


--~--~-~--~~~---~--~~
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: Passing arguments to a nested element

2007-04-21 Thread Gonza

Hi Mariano,

Gracias. Like you said, it's not the most elegant solution but it'll
probably work.

Thanks!
Gonzalo

On Apr 21, 8:55 pm, "Mariano Iglesias" <[EMAIL PROTECTED]>
wrote:
> You can do it through a quick hack, though it is not very elegant. Let's say
> that on your view you have:
>
> renderElement('element1', array('arg1' => 'Hello', 'arg2'
> => 'World')); ?>
>
> And element1 includes element2. Element2 looks like:
>
> 
>
> Then the hack is to make element1 look like:
>
> 
> $loaded = am(array_keys($this->viewVars), array_keys($this->loaded));
> $args = array_diff_key($___dataForView, array_flip($loaded));
>
> echo $this->renderElement('element2', $args);
>
> ?>
>
> -MI
>
> ---
>
> Remember, smart coders answer ten questions for every question they ask.
> So be smart, be cool, and share your knowledge.
>
> BAKE ON!
>
> blog:http://www.MarianoIglesias.com.ar
>
> ____________
> De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
> de Gonzalo Servat
> Enviado el: Sábado, 21 de Abril de 2007 08:35 p.m.
> Para: cake-php@googlegroups.com
> Asunto: Re: Passing arguments to a nested element
>
> .. but not quite the solution I was looking for. What I'm trying to avoid is
> having to specifically write each and every variable in either method. I was
> hoping for a way to grab them all and send the arguments to the next
> renderElement call. Maybe I understood how to use compact? I'd really
> appreciate an example.


--~--~-~--~~~---~--~~
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: Passing arguments to a nested element

2007-04-21 Thread Mariano Iglesias

You can do it through a quick hack, though it is not very elegant. Let's say
that on your view you have:

renderElement('element1', array('arg1' => 'Hello', 'arg2'
=> 'World')); ?>

And element1 includes element2. Element2 looks like:



Then the hack is to make element1 look like:

viewVars), array_keys($this->loaded));
$args = array_diff_key($___dataForView, array_flip($loaded));

echo $this->renderElement('element2', $args);

?>

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar


De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de Gonzalo Servat
Enviado el: Sábado, 21 de Abril de 2007 08:35 p.m.
Para: cake-php@googlegroups.com
Asunto: Re: Passing arguments to a nested element

.. but not quite the solution I was looking for. What I'm trying to avoid is
having to specifically write each and every variable in either method. I was
hoping for a way to grab them all and send the arguments to the next
renderElement call. Maybe I understood how to use compact? I'd really
appreciate an example. 


--~--~-~--~~~---~--~~
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: Passing arguments to a nested element

2007-04-21 Thread Gonzalo Servat
On 4/21/07, Samuel DeVore <[EMAIL PROTECTED]> wrote:
>
>
> one of my favorite php functions these days is http://php.net/compact
>

Thanks for the suggestion. I'm not quite sure how compact will help me,
though. Lets consider this example:

$this->renderElement('element', array('arg1' => 'val1', 'arg2' => 'val2));

Inside 'element' we could do this:

$this->renderElement('element2', compact('arg1', 'arg2'));

which looks a little nicer than this:

$this->renderElement('element2', array($arg1, $arg2));

.. but not quite the solution I was looking for. What I'm trying to avoid is
having to specifically write each and every variable in either method. I was
hoping for a way to grab them all and send the arguments to the next
renderElement call. Maybe I understood how to use compact? I'd really
appreciate an example.

Thanks!

Regards,
Gonzalo.

--~--~-~--~~~---~--~~
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: Passing arguments to a nested element

2007-04-21 Thread Samuel DeVore

one of my favorite php functions these days is http://php.net/compact

On 4/21/07, Gonzalo Servat <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> Say I have:
>
> $this->renderElement('element', array('arg1' => 'val1', 'arg2' => 'val2'));
>
> Once inside element.thtml , how could I render another element and pass
> whatever arguments were passed onto the main element? (ie. arg1, arg2 in
> this case)
>
> I thought of a (untested) workaround, but, it's not very nice. I thought I
> could do something like:
>
> $this->renderElement('element', array('args' => array( 'arg1' => 'val1',
> 'arg2' => 'val2')));
> foreach($args as $key => $val)
> {
> ${$key} = $val;
> }
>
> Inside element.thtml:
>
> $this->renderElement('element2', array($args));
>
> ... but it's too hack-ish. Any other suggestions?
>
> Thanks in advance.
>
> Regards,
> Gonzalo
>
>  >
>


-- 
(the old fart) the advice is free, the lack of crankiness will cost you

- its a fine line between a real question and an idiot

http://blog.samdevore.com/archives/2007/03/05/when-open-source-bugs-me/

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---