![]() |
|
Snippets |
|
In order to delay a page redirect with several seconds, I wrote this simple helper
<?php use_helper('Javascript'); /** * Adds javascript code to delay a page redirect * * @param string 'module/action' or '@rule' of the action (same argument as url_for()) * @param int time of delay in seconds. Default = 5 * @return JavaScript tag for delayed page redirect */ function delayed_redirect($internal_uri, $time = 5) { sfContext::getInstance()->getResponse()->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); $code = 'new PeriodicalExecuter(function() { location.href=\''.url_for($internal_uri).'\';}, '.$time.')'; return javascript_tag($code); }
See http://www.symfony-project.com/book/1_0/07-Inside-the-View-Layer#Adding%20Your%20Own%20Helpers for information on how to add your own helper
There is no method given by Symfony to redirect to module/action of an other application. Redirect method of SfActions permit only to redirect to module/action of the current application or to an url.
In the forum fabien say, it is because applications are independant.
But it could be usefull for a backend (generated with admin generator), to add a new "object_actions" which permit to view the result of a record (an article for e.g.) by redirecting to the article webpage in the frontend.
Then you can add in the Actions class an action method like :
public function executeView() { $this->redirect("http://".$this->getContext()->getRequest()->getHost().'/article/'.$this->getRequestParameter('id')); } // or if the application is not the default application (behind index.php) and the application is named "frontend" public function executeView() { $applicationName='frontend'; $this->redirect("http://".$this->getContext()->getRequest()->getHost().'/'.$applicationName.'.php/article/'.$this->getRequestParameter('id')); }
To add this action in the backend, add this line to generator.yml :
generator:
param:
list:
object_actions:
_edit: -
view: { name : View this article, action: view, icon: backend/view.png }