0

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.

2
  • You can't do that using $this->Html->css(). Commented May 15, 2017 at 10:44
  • @AIPDTECH How can i do it then? Commented May 15, 2017 at 10:52

2 Answers 2

1

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" />

Sign up to request clarification or add additional context in comments.

Comments

0

Simply pass ['ext' => false] as the second argument ($options):

$this->Html->css($mycss, ['ext' => false]);

Source code: src/View/Helper/HtmlHelper.phpsrc/View/Helper/UrlHelper.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.