Hi .
On Tue, Jun 24, 2008 at 11:28 AM, . <[EMAIL PROTECTED]> wrote:
> I have a controller comments_controller.php and comments/add.ctp file, but I
> want to be able to add this add.ctp onto more than 1 page (don't want to
> duplicate the same code). Should I make an elements/comments/add.ctp instead
> of view/comments/add.ctp?
You can do both ways, see requestAction("/comments/add") and
element("/comments/add") in the manual.
The "element" way will probably be a better choice, as you should need
no controller logic (action) to render a simple form in several
places...
AFAIK, the ultimate choice depends more on your controller logic : how
will the result be saved and displayed, will it be ajax or will it be
redirected, will there be validation, ? etc...
> Also, in my elements/add.ctp file, if I do <? echo $variable; ?>, and in my
> comments_controller.php file I do $this->set('variable', 'test');, it gives
> me an error. How would I do this the right way?
You must set the variables for the elements in the element() function :
$this->element("/comments/add",array("variable"=>"test"));
+++++++++
Clément
>
> Thanks
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---