如何在Zend Framework中编写内部样式表?

Mar*_*cel 3 css php zend-framework

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

<head>
   <style type="text/css" media="all"> 
      body{ background: #FFFFFF; }
   </style>
</head>
Run Code Online (Sandbox Code Playgroud)

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

但是我找不到编写内部样式表的方法.有任何想法吗?

jas*_*son 14

您正在寻找的是HeadStyle视图助手.其手册文档可在此处找到.

HeadStyle助手的API是一致的将所有Head*视图助手,和作品本身(以下假设你是在一个viewscript):

// 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() ?>
Run Code Online (Sandbox Code Playgroud)

请注意,您不在<style>任何此输入中包含标记.这是由助手本身产生的.然后,在您的布局中,只需要echo您希望其输出的帮助器:

<head>
    <?php echo $this->headLink() ?>
    <?php echo $this->headStyle() ?>
</head>
Run Code Online (Sandbox Code Playgroud)