views:

359

answers:

1

Hi,

Just like I did 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 website and view source, there are duplicated 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 is going on with my code??

+5  A: 

You shouldn't echo them all individually.

There should be one place where the HeadLink helper is printed, and all the other calls only add the stylesheet to that helper to be printed. E.g. the following rules anywhere in your 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 in your <head>:

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

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

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

which will print the contents of the HeadLink helper with those 3 stylesheets attached.

Also see the HeadLink helper Zend documentation; the example in particular.

mercator
ah!! great!! thanks!!
Moon