Netcars provide cheap car loans and instant car finance online.
Great deals on car insurance from Direct Line
Save money - get a car insurance quote from privilege
adverts
 

Every so often, at the beginning of a new project at work, I almost always have to add a page-specific stylesheet to a certain page on the project. And usually (almost always it seems) I forget the exact code to enter at the top of the .phtml page.

And I thought I should blog it, so that at least I remember it for future use…

This is for Zend Framework-built sites only, of course, and so long as this is in your <head> section of your bootstrap Index file…

<?php
echo $this->headTitle();
echo $this->headScript();
echo $this->headStyle();
echo $this->headLink();
?>

…Then, on the page we’re talking about, before output on your .phtml file, add the following code

$this->headLink()->appendStylesheet('/path/to/page-styles.css');

Done! So there you are. Some of you might have already known that, maybe some of you have no idea what I’m talking about – but at least I know where to find this damn code again!

 
 

Don't forget Dazecoop

 
keep track of my tweets :)
 
For cheaper car insurance, there is only one place to go and that's Hastings Direct!

4 comments so far

  • Tim Elliott
    12 Dec 2008 at 5:01 pm

    So I enter “zend css style sheet” into google and guess what I find…
    Cheers mate, still bailing me out on code!
    There’s so many cocking functions, it’s easy to get lost in ZF.

    BTW, happy bday!

    Tim

  • Daze
    15 Dec 2008 at 8:27 am

    Hehe, sweet nice one! Does the job, eh?

    Thanks very much! Haven’t heard from ya in a while, hope things are all well buddy!

    Daze.

  • [...] David Cooper posted a quick howto on adding CSS to a Zend Framework page, which works and is all well and good, but there was a problem. The code that Zend Framework spits [...]

  • POC
    11 Dec 2009 at 12:13 pm

    Do you know a why to set the media attribute via the zend API? I need to be able to define a print.css and ensure the media=”print” attribute is set. So that the final html looks like :

What do you think?

 
wordpress
Theme by David Cooper :)