我在布局上使用 $this->headLink()->appendStylesheet()
设置了少量样式,并且我正在尝试从 View 内部附加另一个样式表。但是, View 中的样式表始终是 headLink 堆栈中渲染的第一个样式表。
布局.phtml:
echo $this->headLink()->appendStylesheet($this->basePath('css/styleA.css'))
->appendStylesheet($this->basePath('css/styleB.css'));
然后在 View 中我尝试了以下操作
查看.phtml:
$this->headLink()->appendStylesheet($this->basePath('css/sub/styleC.css'));
和
$this->headLink()->offsetSetStylesheet(100, $this->basePath('css/sub/styleC.css'));
但是,两者最终都以 styleC 为呈现的第一个链接标记。我知道 subview 首先渲染(即,view.phtml 在layout.phtml 之前渲染),但我认为只要渲染器相同,像 headLink 和 headScript 这样的助手就有一个共享堆栈。这个假设错了吗?
最佳答案
您需要在布局中添加样式表,例如:
echo $this->headLink()->prependStylesheet($this->basePath('css/styleB.css'))
->prependStylesheet($this->basePath('css/styleA.css'));
并像之前一样在 View 中附加样式表。
关于php - ZF2 headLink 辅助订购,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17790536/