开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜