2010年8月19日星期四

Re: [fw-mvc] How to use placeholder based helpers on multiple outputs

Perhaps a simpler way to handle your use case is to decouple the form
presentment from the act of processing and emailing the data, and
therefore have two (or three) separate actions for them. This would
allow for easier, more readable code and would make the views simpler
as well.

I have similar schemas in my applications. Using the example you used
of a contact application, I would have any request to send a contact
email proxy to a ContactController:

class ContactController extends Zend_Controller_Action
{
init()
{
$this->view->headLink()->appendStylesheet('/css/controllerst/common.css');
// other initialization code here...
}

indexAction()
{
$this->view->headTitle("My Contact Form");
$this->view->headLink()->appendStylesheet('/css/controllers/contact/form.css');
// present contact form
}

sendEmail()
{
// process and send the email
// forward to successAction() upon success
}

successAction()
{
// email sent successfully
$this->view->headTitle("Email Sent!");
$this->view->headLink()->appendStylesheet('/css/controllers/contact/success.css');
}
}

This is the general schema I use to accomplish what you are doing, and
this is, of course, one of many ways to accomplish this goal. IMHO,
this is much simpler, and maybe more in keeping with the intended
usage of the headTitle, -Script, -Link, -Style placeholder helpers the
Zend devs had in mind.

--regards,
nathan

On Thu, Aug 19, 2010 at 5:24 AM, Cristian Bichis <cristi@imagis.ro> wrote:
> Hi,
>
> A normal application may have multiple ways to interact with user. There is
> the application/website itself, the emails sent by app to users, RSS feeds,
> aso.
>
> I noticed one problem when working with placeholder helpers (headtitle,
> headlink, aso) on multiple such outputs at the same time.
>
> Let's take a simple case: let's suppose we have the contact action. This
> action does 2 things:
>
> 1. It renders a form
>
> 2. Sends an email once the form is submitted
>
> Both the action generated page and the email have a layout behind.
>
> The problem is the styles, titles, scripts are actually merged for both of
> layouts: the one for email and the one for website.
>
> I think the solution is to set different containers for the helpers on email
> layout and website layout, at each call. Something like this:
>
> $container = new Zend_View_Helper_Placeholder_Container();
> $this->headTitle($itle)->setContainer( $container );
>
> This is supposed to fully solve the problems ?
>
> Cristian
>

没有评论: