Zend Framework:如何从 HeadLink 帮助程序中取消设置一个样式表

发布于 2024-11-16 08:03:08 字数 514 浏览 5 评论 0原文

我在 Controller init() 中有一个常见样式列表:

$this->view->headLink()->setStylesheet('/style/style.css');
$this->view->headLink()->appendStylesheet('/style/style2.css');
$this->view->headLink()->appendStylesheet('/style/style3.css');
$this->view->headLink()->appendStylesheet('/style/forms.css');
$this->view->headLink()->appendStylesheet('/style/ie_patches.css','all','lte IE 7');

我需要的是稍后在该控制器的某个操作中从堆栈中删除其中一个样式表的方法。

感谢您的帮助, 请原谅我的英语

I have in Controller init() a list of common styles:

$this->view->headLink()->setStylesheet('/style/style.css');
$this->view->headLink()->appendStylesheet('/style/style2.css');
$this->view->headLink()->appendStylesheet('/style/style3.css');
$this->view->headLink()->appendStylesheet('/style/forms.css');
$this->view->headLink()->appendStylesheet('/style/ie_patches.css','all','lte IE 7');

what I need is the way to remove one of the stylesheets from the stack later in one of the action of this controller.

Appreciate your help,
excuse my English

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

衣神在巴黎 2024-11-23 08:03:08

或者您可以使用

$this->view->headLink()->offsetUnset($offsetToBeRemoved); // offsetToBeRemoved should be integer

要找出 offsetToBeRemoved 您可以获取迭代器( $this->view->headLink()->getIterator() )或容器 $this ->view->headLink()->getContainer() ),循环遍历它并获取您感兴趣的密钥。

OR you can use

$this->view->headLink()->offsetUnset($offsetToBeRemoved); // offsetToBeRemoved should be integer

To find out the offsetToBeRemoved you can either get the iterator ( $this->view->headLink()->getIterator() ) or the container $this->view->headLink()->getContainer() ), loop thru it and get the key you're intrested in .

一桥轻雨一伞开 2024-11-23 08:03:08

例如,如果您想删除 '/style/style2.css',您可以在操作中执行如下操作:

    $headLinkContainer = $this->view->headLink()->getContainer();
    unset($headLinkContainer[1]);

这是有效的,因为容器(即 Zend_View_Helper_Placeholder_Container 的实例)扩展了 ArrayObject。这意味着您可以像使用数组一样操作 headLink 元素。

希望这有帮助。

For example, if you want to remove '/style/style2.css' you can do in an action as follows:

    $headLinkContainer = $this->view->headLink()->getContainer();
    unset($headLinkContainer[1]);

This works because the container (i.e. instance of Zend_View_Helper_Placeholder_Container) extends ArrayObject. This means that you can manipulate your headLink elements as if you were using an array.

Hope this helps.

寄风 2024-11-23 08:03:08

您还可以像这样设置空容器:

$this->view->headLink()->setContainer(
    new Zend_View_Helper_Placeholder_Container()
);

You can also set empty container like this:

$this->view->headLink()->setContainer(
    new Zend_View_Helper_Placeholder_Container()
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文