True, this is the "callbacks queue" version.
I've attached you the class i'm using now.
An example could be this one:
In your controller, maybe you want to retrieve a saved URI (a filtered view
of the customers list: http://www.example.com/customers/list/search/tr
$uri = Custom_Classes_CallbackHelper::get('default', 'customers','list',
'customers/list');
Note: the last parameter is the default uri in case the saved uri has been
deleted from the stack in any previous moment.
----
NOTE:
In the boostrap i've this piece of code too:
(Let the bootstrap save the last callbacks automatically for you)
try {
Zend_Controller_Front::run($controllers);
if($control->isLogged()) {
// the user is logged, we save the request into the
callback's stack
// NOTE: the viewless controllers does not save his callback
because the response is redirected before we'll
// get at this point, so we can save memory and cpu time
omitting the controllers callback (i.e. user update form processing)
$request = $zcf->getRequest();
Custom_Classes_CallbackHelper::save($request->getModuleName(),
$request->getControllerName(), $request->getActionName());
}
}
catch (Exception $e) {
echo $e->getMessage();
}
2007/9/5, Mauro Casula <[EMAIL PROTECTED]>:
>
>
> Have you a pice of code doing that?
> --
> View this message in context:
> http://www.nabble.com/How-to-set-a-session-variable-and-return-exactly-to-caller-action-tf4382330s16154.html#a12493276
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>
--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[EMAIL PROTECTED]
http://web.xaviervidal.net
610.68.41.78
<?php
class Custom_Classes_CallbackHelper
{
const MAX_URL_NUMBER = 20;
public static function save($module, $controller, $action, $url = null)
{
$session = new Zend_Session_Namespace();
// set default module?
$module = (is_null($module)) ? 'default' : $module;
// set server url?
$url = (is_null($url)) ? $_SERVER['REQUEST_URI'] : $url;
// get the callbacks
$callbacks = (!isset($session->callbacks)) ? array() : $session->callbacks;
// save the callback count
$callbacksCount = count($callbacks);
// search if the callback exists
$found = false;
for($i = 0; $i < $callbacksCount; $i++) {
if($callbacks[$i]['tag'] == "$module-$controller-$action") {
$callbacks[$i]['url'] = $url;
$found = true;
break;
}
}
if(!$found) {
// didn't exists, so save the passed url
$callbacks[$callbacksCount]['tag'] = "$module-$controller-$action";
$callbacks[$callbacksCount]['url'] = $url;
}
// let's take a look if we reach the array limit
if(($callbacksCount + 1) > self::MAX_URL_NUMBER) {
// we can throw the first element of the stack
array_shift($callbacks);
}
// store the callbacks in the session
$session->callbacks = $callbacks;
}
public static function get($module, $controller, $action, $defaultIfNotFound)
{
$session = new Zend_Session_Namespace();
$module = (is_null($module)) ? 'default' : $module;
// there's no info in the session, so return the default callback
if(!isset($session->callbacks)) {
return Zend_Registry::get('application.baseurl') . $defaultIfNotFound;
}
// let's search through the callbacks, searching for the special tag
$callbacks = $session->callbacks;
foreach($callbacks as $callback) {
if($callback['tag'] == "$module-$controller-$action") {
// found!, so return the URL
return $callback['url'];
}
}
// oops, there's no tag for the request, so return the default URL
return Zend_Registry::get('application.baseurl') . $defaultIfNotFound;
}
}