【问题标题】:How do I write internal style sheets in Zend Framework?如何在 Zend Framework 中编写内部样式表?
【发布时间】:2009-08-05 02:26:23
【问题描述】:

我想在 Zend Framework 中为视图编写内部样式表

<head>
   <style type="text/css" media="all"> 
      body{ background: #FFFFFF; }
   </style>
</head>

我知道我可以使用$this-&gt;view-&gt;headLink()-&gt;appendStylesheet('style.css'); 编写外部样式表

但是我找不到编写内部样式表的方法。有什么想法吗?

【问题讨论】:

  • 请澄清您所说的“内部样式表”是什么意思。
  • 编辑问题以澄清内部样式表

标签: php css zend-framework


【解决方案1】:

您正在寻找的称为HeadStyle 视图助手。它的手册文档可以在here找到。

HeadStyle 助手的 API 与所有 Head* 视图助手一致,并按此方式工作(以下假设您在视图脚本中):

// Putting styles in order: 
// These methods assume the a string argument containing the style rules.

// place at a particular offset:
$this->headStyle()->offsetSetStyle(100, $customStyles);

// place at end:
$this->headStyle()->appendStyle($finalStyles);

// place at beginning
$this->headStyle()->prependStyle($firstStyles);

// Or capturing a block of styles

<?php $this->headStyle()->captureStart() ?>
body {
    background-color: <?php echo $this->bgColor ?>;
}
<?php $this->headStyle()->captureEnd() ?>

请注意,您不要在任何此输入中包含&lt;style&gt; 标记。这是由助手本身生成的。 然后,在您的布局中,只需 echo 您希望其输出的助手:

<head>
    <?php echo $this->headLink() ?>
    <?php echo $this->headStyle() ?>
</head>

【讨论】:

  • 谢谢。 $this->headStyle()->captureStart() 和 $this->headStyle()->captureEnd() 正是我想要的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-15
  • 1970-01-01
  • 1970-01-01
  • 2016-04-14
  • 2012-06-09
  • 2014-06-22
相关资源
最近更新 更多