$ this-> headLink () includes a duplicate script

As before, I used the following code for my new project.

<?=$this->headLink()->appendStylesheet('/Layouts/admin/css/button.css');?>
<?=$this->headLink()->appendStylesheet('/Layouts/admin/css/inputText.css');?>
<?=$this->headLink()->appendStylesheet('/Layouts/admin/css/fancyTable.class.css');?>

when I open the site and browse the source code, there are duplicate css link tags.

<link href="/Layouts/admin/css/button.css" media="screen" rel="stylesheet" type="text/css" ><link href="/Layouts/admin/css/button.css" media="screen" rel="stylesheet" type="text/css" >
<link href="/Layouts/admin/css/inputText.css" media="screen" rel="stylesheet" type="text/css" ><link href="/Layouts/admin/css/button.css" media="screen" rel="stylesheet" type="text/css" >
<link href="/Layouts/admin/css/inputText.css" media="screen" rel="stylesheet" type="text/css" >
<link href="/Layouts/admin/css/fancyTable.class.css" media="screen" rel="stylesheet" type="text/css" >

<link href="/Layouts/admin/css/button.css" media="screen" rel="stylesheet" type="text/css" >
<link href="/Layouts/admin/css/inputText.css" media="screen" rel="stylesheet" type="text/css" >
<link href="/Layouts/admin/css/fancyTable.class.css" media="screen" rel="stylesheet" type="text/css" >
<link href="/Layouts/admin/css/divine.css" media="screen" rel="stylesheet" type="text/css" >

What happens to my code?

+3
source share
1 answer

You do not have to send them all individually.

There must be one place where the HeadLink helper is printed, and all other calls only add a stylesheet to this print helper. For example. the following rules in view scripts:

<?php $this->headLink()->appendStylesheet('/Layouts/admin/css/button.css'); ?>
<?php $this->headLink()->appendStylesheet('/Layouts/admin/css/inputText.css'); ?>
<?php $this->headLink()->appendStylesheet('/Layouts/admin/css/fancyTable.class.css'); ?>

And then this is in yours <head>:

<?= $this->headLink() ?>

Or, if they all go in the same place, you can tie them together

<?= $this->headLink()
    ->appendStylesheet('/Layouts/admin/css/button.css')
    ->appendStylesheet('/Layouts/admin/css/inputText.css')
    ->appendStylesheet('/Layouts/admin/css/fancyTable.class.css'); ?>

HeadLink 3 .

. Zend HeadLink Zend; .

+11

Source: https://habr.com/ru/post/1724557/


All Articles