Can I insert a style tag and contents from a view with CakePHP?
From what I can see, Cake开发者_StackOverflowPHP makes it easy to link to a CSS file in a view with the following:
echo $html->css('my-css-filename',null,array(),FALSE);
But what if I don't want to exclusively use hardcoded files? How can I get it to create a style tag with some dynamically generated rules in e.g.
<style type="text/css" media="all">p {font-size:1.5em}</style>
I am trying to do this in a view file, I'd like the CSS to be placed in the head tag, and I'm using CakePHP 1.2.7
I'd just pass the variable from the controller to the view as you normally would.
In your controller,
function test() {
// do some stuff
$dyn-css = 'p { font-size: 1.5em }';
$this->set( 'dyn-css', $dyn-css );
}
Then in your layout file:
<head>
<?php echo $dyn-css; ?>
// other stuff
</head>
精彩评论