War Coder
War Coder

Reputation: 464

CSS not applying correctly in Zend Framework

I am new to the Zend framework.

If I access my Zend application by going to http://localhost/zendapplicationfolder/contact it displays correctly with css applying correctly but if I access the Zend application by going to http://localhost/zendapplicationfolder/contact/ (added a forward slash), the page displays but css is not applied, but if I view the source, the css link is embedded normally between the head tags.

Upvotes: 0

Views: 6444

Answers (3)

fleire
fleire

Reputation:

I thought I had to change something to my codes when the stylesheets were added. Turns out that all I needed to change was to add the forward slash as pointed out by gaoshan88 (thank you!):

href="stylesheets/main3.css"
to
href="/stylesheets/main3.css"

Upvotes: 0

rg88
rg88

Reputation: 20977

Without knowing your project layout I suspect that you could solve the problem by using /css/screen.css rather than css/screen.css That forward slash would give you an absolute path to your css directory rather than the relative one you are using.

For example, this works: <?php echo $this->headLink()->appendStylesheet('/css/main.css') ?> while this does what you describe: <?php echo $this->headLink()->appendStylesheet('css/main.css') ?> the only diff is the forward slash in front of css.

Upvotes: 1

Itay Moav -Malimovka
Itay Moav -Malimovka

Reputation: 53606

The dcode to include the CSS should be in a layout file, and should use the baseurl helper instead of manually writing the link to the css file.

Helper class:

class Zend_View_Helper_BaseUrl
{
    function baseUrl()  {
        return Zend_Controller_Front::getInstance()->getBaseUrl();
    }
}

Code in the layout:

<link rel="stylesheet" type="text/css" media="screen" href="<?=$this->baseUrl();?>/your/path/from base url/your.css" />

Upvotes: 4

Related Questions