Also, If you want to move as much code out of individual controllers as possible you can put the get message calls into the app_controller.php constructor.

class AppController extends Controller {

function AppController()
{
parent::__constructor();

$systemMessage = $this->getSystemMessage();
$errorMessage     = $this->getErrorMessage();

if ($systemMessage !=0) {
$this->set('systemMessage', $systemMessage);
}

if ($errorMessage !=0) {
$this->set('errorMessage', $errorMessage);
}

}
}


From there your other controller code is less cluttered.  Your view stays the same, just checking to see if the variable is set.

On 5/20/06, John Zimmerman [gmail] <[EMAIL PROTECTED]> wrote:
A work around would be to create a function in your app controller called

setSystemMessage($message);

this function would set a session variable with the message.

Then create another function called ...

getSystemMessage()

This function will return the contents of the session variable and then unset it.  If the session variable is not set it will return 0.

So in your controller you would setSystemMessage('Success!') then redirect to the same page.

Also in your controller before rendering the view you would do the following...

$systemMessage = $this->getSystemMessage();

if ($systemMessage !=0) {
$this->set('systemMessage', $systemMessage);
}


In your view to that page you would have an if statement like the following...

if ( isset($systemMessage)) {
    echo $systemMessage;
}


Style the system message by putting it within <div class="system_message"> or something similar.


You can create the same kind of functions for setErrorMessage and getErrorMessage and do the same thing in the controller/view.  Then style it with <div class="error_message">

This will work just fine as I am doing something similar with another application using another framework.  Using the session variable should clear any of the problems you were having.


On 5/20/06, josh southern < [EMAIL PROTECTED]> wrote:

The problem with redirect() is that the variable I use to display the
success message doesn't carry through. The problem with flash() is that
if a user looks away for a few seconds (let's say the phone rings, or
someone walks into the room), they miss the success message and it
creates confusion as to whether the form worked. Hence my solution of
displaying a message on top of a new, blank form. They're already used
to looking there because of the validation error messages, and if they
distracted for a few seconds, they don't miss the success message.

This worked fine before, and now with 1.0, it doesn't. Can't someone
tell me why, and if there is a way for me to code a work-around?




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to