[Midas] Notification.php

Zach Mullen zach.mullen at kitware.com
Wed Jul 4 13:58:41 EDT 2012


If you're making an ajax call from a page, the best way to display an error
message is to echo JSON in your controller and then in your javascript, if
you detect an error condition in the response, call midas.createNotice().

Example, in your controller:

$this->disableLayout(); // disable layout view
$this->disableView(); // we don't want HTTP view rendered, just a JSON
response

... if error condition detected...
  {
  echo JsonComponent::encode(array('status' => 'error', 'message' =>
'Something went wrong'));
  return;
  }

Then, in your javascript response callback function,

var resp = $.parseJSON(responseText);
midas.createNotice(resp.message, 5000, resp.status);

If your status is set to 'error', it will display the notice with an error
icon.  If the status is 'warning', it will display as a warning.
 Otherwise, it will display with the 'ok' status, which is a green check
mark.


If you are making a normal controller call with a view, you can either
throw an exception, which will render an error view, but that is rather
ugly.  If you want a more human readable error view, just pass some sort of
variable down to your view that causes the view to display the error
condition.

Thanks,

Zach


On Wed, Jul 4, 2012 at 1:51 PM, Mona Wong <mona at sdsc.edu> wrote:

>
>         What's a good way to display an error message to the user?  I am
> writing a controller but if something goes wrong, I'd like to inform the
> user.
>
>         I looked at the remoteprocessing module and tried:
>
>         if ( $itemid == null )
>         {
>             throw new Zend_Exception ( "ERROR: missing item id, cannot
> continue!" );
>             return;
>         }
>
>         But that didn't work...just gave me a blank page.  What am I doing
> wrong?
>
> thanks,
> Mona
>
> *********************************************
>     Mona Wong
>     Web & iPad Application Developer
>     San Diego Supercomputer Center
>
>     Believing we are in control is an
>     illusion that brings suffering.
> *********************************************
>
>
>
>
>
> _______________________________________________
> Midas mailing list
> Midas at public.kitware.com
> http://public.kitware.com/cgi-bin/mailman/listinfo/midas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/midas/attachments/20120704/8a037336/attachment.html>


More information about the Midas mailing list