phpcakephpcakephp-2.6

How to remove .css extension from Html->css method selectively in CakePHP?


I am dynamically generating css from a php file (custom2.php) and setting its content-type to "text/css" to render css in client view.This php file is located at css folder inside webroot directory. It works great when i load it with complete path. But when i use Html helper to load php file. It automatically appends ".css" extension to it. Because of which, Apache doesn't render php file and treat it as css file by default..

When i load it with complete path (It works) like this:-

<link rel="stylesheet" href="/Project1/css/custom2.php" />

But when i load it in standard cakephp way(It doesn't work) like this:-

echo $this->Html-css("$mycss");  
/* It loads file after adding .css extension(custom2.php.css) which i don't want */

I am passing php file from Controller(index action) like this:-

$this->set('mycss','custom2.php');

However, adding css extension is default behavior of Html helper and i want it to remain so except when i am linking any php file. Is there any inline method to disable css extension generation at particular situation/condition?

PS: I want to use standard cakephp method to load css to avoid broken link issue with different controller and view.


Solution

  • You can use $this->webroot for base url. So in your case

    <link rel="stylesheet" href="<?php echo $this->webroot; ?>css/custom2.php" />

    and if you want comple url, try this

    <link rel="stylesheet" href="<?php echo Router::url('/', true); ?>css/custom2.php" />