开发者

Zend Framework - How to call a CSS inside a view?

I would like to inje开发者_StackOverflow社区ct a css on a header, on a specific view. I've looked into Zend manual and it talks about some sort of helper class for doing so. However, I'm not sure if we have all helpers available to us.

Do we have that helper class always available?

What would be an example of doing such a thing?


It's one of the core helpers, so you'll definitely have it available unless you've got a very exotic setup. From the manual, typically you'll want to do something like:

$styles = 'div#myDiv{margin:10px;padding:10px;}';
$this->headStyle()->appendStyle($styles);

in your view file to initialise your style. In your layout file you'll need to then echo out what you've appended using:

echo $this->headStyle();

Note that both the initialising and that final echo are required.

Edit: this assumes you're doing it inline - if you want to inject a linked CSS file then you'll use the headlink helper; that's the same deal, you initialise it and then echo it out in your layout.


$this->headLink()->appendStylesheet('/css/style.css');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜