I'd do something like this: create an element for each flash chunk you
want to display, then store the references in the session - separately
from the normal flash data.

/app/elements/flash-email-not-unique.ctp :

<div class="flash-chunk">
 <h3>Email not unique</h3>
 <p>
Someone is already using the email address <var><?php echo
htmlentities($email); ?></var>; to view their information <?php echo
$html->link('click here', '/users/view/' . $user_id, array('title' =>
'\'Click here\' is really bad link text')); ?>.
 </p>
</div>

/app/controllers/users_controller.php :

function add() {
  // ... bla bla bla
  if (...) {
    // Want to display flash chunk - pass view parameters (user_id and
email)
    $this->Session->write('MyFlash', array('chunk' => 'email-not-
unique', 'user_id' => $foo, 'email' => $bar));
  }
}

/app/views/layouts/default.ctp
(before/after where the normal flash bit is)

<?php
if ($session->check('MyFlash')) {
  $chunk_info = $session->read('MyFlash');
  $session->del('MyFlash');
  $chunk_name = 'flash-' . $chunk_info['chunk'];
  unset($chunk_info['chunk']);
  echo $this->renderElement($chunk_name, $chunk_info);
}
?>

Of course, this is just a base idea - you could easily extend this to
having multiple 'chunks' displayed and so forth. But the basic idea
is: if what you are going to display is more complicated than simple
text, then it should be rendered by a view (here, an element).

You might also want the model to specify what error is to be
displayed, then for the controller to interpret this, rather than
having the controller do it directly.

Hope this helps (and works)

On Sep 9, 6:34 pm, David <[EMAIL PROTECTED]> wrote:
> Hi guys,
>
> Here are situations where one might want to include a link in a flash.
> For example, my app sometimes generates random user passwords. If a
> user has one of these passwords, I would like to flash 'If you would
> like to change your password, click here' when they log in.
>
> The same thing is conceivable with validation errors. Imagine I am
> checking that a registering user's email doesn't already exist in the
> database, and if it does I want to generate an error message like
> 'someone is already using this email address. To view their
> information, click here'.
>
> I suppose the fundamental problem is that flashes are really part of
> the view rather than the controller, but as they are generated in the
> controller you don't have access to helper methods for generating
> links, etc.
>
> I would like to know if anyone has tackled this problem in their app,
> and if so what technique they used to go about it. Any ideas?
>
> Thanks!
>
> David


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

Reply via email to