Code snippets for symfony 1.x



This filter will automatically add css file with the name of current module.

It's great to have these files saved separately that to have one huge file. (And demo of CSSEdit doesn't allow saving files bigger than 2.5k chars :D)

Just create your cssAdderFilter.class.php, and add it to your filters.yml. Clear cache and you are ready to go.

class cssAdderFilter extends sfFilter
    public function execute( $filterChain )
        $context = $this->getContext();
        $request = $context->getRequest();
        $response = $context->getResponse();
        $module = $request->getParameter("module");
        $path_to_web = sfConfig::get("sf_web_dir");
        $path_to_css = $path_to_web . "/css/" . $module . ".css";
        if (file_exists($path_to_css))
by zero0x on 2008-05-10, tagged asset  css  filter 

Comments on this snippet

gravatar icon
#1 Thomas Boerger on 2008-05-13 at 09:29

I think you dont need to add the file_exists check. If it doesnt exist it wont be included ;).

gravatar icon
#2 zero0x on 2008-05-13 at 03:16

aha:) I didn't know that, thanks

gravatar icon
#3 Martin Poirier Theoret on 2008-05-29 at 01:37

I think that this snippet

is covering that in a more complete and efficient way...

Ok I know it's mine ;O)

I do think that's a good thing to chekc if the file exist because if you don't it will be put in your HTML and the request to retrieve it from the server will be done... of course if the file doesn't exist nothing will append but a file_exists will produce a cleaner code and will (I think) be less ressource using then a useless server call.