![]() |
|
Snippets |
|
A simple filter for Symfony 1.2.* which embed a js per request named after /js/modules/:module_:action.js rule.
<?php class JsModuleActionFilter extends sfFilter { public function execute($filterChain) { if ($this->isFirstCall()) { $params = $this->getContext()->getRequest()->getRequestParameters(); //gets a module action specific js file $this->getContext()->getResponse()->addJavascript('modules/' . $params['module'] . '_' . $params['action'] , 'last'); } $filterChain->execute(); } } ?>
Comments on this snippet
In 90% of your pages you won't have the corresponding Javascript, and your browser will load a useless 404 when trying to get this script :/
Perhaps it would be cool to be able to activate this snippet on a module/action basis. With a flag or a yaml...