gpt4 book ai didi

css - $document->addStyleSheet 弃用

转载 作者:行者123 更新时间:2023-11-28 14:44:12 27 4
gpt4 key购买 nike

在我的 Joomla 组件中,我根据 phpstorm is $document->addStyleSheet deprecated 添加了一个样式表。

这是我使用的代码:

$uri = JUri::base();
$document = JFactory::getDocument();

$document->addStyleSheet(JUri::base() . "components/com_exampe/views/stats/tmpl/style.css");

我也试过这段代码:

JHtml::stylesheet('com_hccxmlkadernet/views/statistiek/tmpl/style.css', array(), true);

但这也被弃用了

有人能告诉我正确的方法是什么吗?

最佳答案

根据这个页面: https://api.joomla.org/cms-3/classes/Joomla.CMS.Document.Document.html#method_addStyleSheet

上面写着 addStyleSheet() 已弃用。实际上整个方法并没有被弃用,只是预期的参数略有改变。

v4.0 (url, mime, media, attribs) method signature is deprecated, use (url, options, attributes) instead.

所以,只要你用;

$document->addStyleSheet($url)

您无需担心任何事情,一切顺利(因为 arg1 在两个版本中都是 $url)。

不要使用 JHTML。它已在 J2.5 中弃用并从 J3.x 中删除:

It used to be possible to do this with JHTML, however, this was deprecated in Joomla 2.5 and removed in Joomla 3.x.

引用:https://docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page

关于css - $document->addStyleSheet 弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52517838/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com