Using SAUI for Smart Redirects

The preferred method of redirecting (after a successful save, etc.) is to use the smartRedirect() method of the Avhistory Component:

$this->Avhistory->smartRedirect($destination = array(), $msg '', $options = array());

What's So Smart About It?

This method is "smart" because it handles several things:

  • factors in request-type: different things happen for ajax requests vs. traditional requests
  • automatically sets the $this->Session->setFlash() message for you
  • You can specify/hard-code url to redirect to (in this case action=>index).  This redirect will occur for BOTH ajax and non-ajax requests, unless you have 'ajaxFollow' set to false
  • If you specify a null destination, the system will attempt to $this->Avhistory->goBack(1);  This will result in redirecting back to the last page loaded for traditional requests.  For ajax requests, redirecting will exit and not redirect (regarding ajax requests, a null location is the same as specifying a location and passing an $option['ajaxFollow'] = false)

Best Practices / Examples

Typical usage: (ajax requests will exit (so flash messages will be shown at current user location)) while non-ajax requests will redirect to the index action (and output the flash message there)

$this->Avhistory->smartRedirect(array('action' => 'index'), 'Your Snippet has been saved.', array('success'=>true, 'ajaxFollow' => false));

Smart Redirect Options

Parameter NameDefaultExplanation
url null set to id of newly added record and system will redirec to /current controller/edit/$options['url'] or a full url will override the $destination parameter
redirect true Set to false to not redirect (applies to BOTH ajax and non-ajax requests)
success false Set to true to show green checkmark messages (instead of orange notice messages, default)
ignoreHere false Won't use the Avhistory::returnToHere variable (set to redirect users back to starting point during add/edit actions)
ajaxFollow true Ajax-specific redirect setting.  When false, ajax requests will exit without redirecting
1-207-221-3255 | Contact Site Avenger - Your Content Management Superhero

Copyright © 2023 Saco Design, Inc. | All Rights Reserved | Website Design by Saco Design | Superpowered by Site Avenger