1

i created a controller and actions in zend. if i type "http://localhost/cms/public/controller" then the css file is loaded correctly but if i type "http://localhost/cms/public/controller/action"

then headlink appears like

href='http://localhost/cms/public/controller/css/style.css" and it does not work. Please help me!!

1

2 Answers 2

4

this is the correct way to add css & javascript to ZF Application

 <?php
        $this->headLink()->appendStylesheet($this->baseUrl("css/reset.css"))
                ->appendStylesheet($this->baseUrl("css/text.css"))
                ->appendStylesheet($this->baseUrl("css/960.css"))
                ->appendStylesheet($this->baseUrl("css/demo.css"));
        echo $this->headLink();
        $this->headScript()->appendFile($this->baseUrl("js/jquery-1.4.2.min"))
                    ->appendFile($this->baseUrl("js/jquery-ui-1.8.2.custom.min"));
            echo $this->headScript();?>
Sign up to request clarification or add additional context in comments.

Comments

1

You have your css path set to "css/style.css". Set the css path relative to the root path. If your css is in /html/style/css/style.css, the link would be "/style/css/style.css"

Always remember the leading slash and make the static paths relative to the root dir(of the website).

3 Comments

I think my webserver is looking for css file inside /controller folder inside my root directory. Could you please tell me where can i find this url root path.
I think i did $this->headLink()->appendStylesheet('css/layout.css'); echo $this->headLink(); in my layout.phtml file. Do i have to add root path right here?
$this->headLink()->appendStylesheet('/css/layout.css'); echo $this->headLink(); Try this line. If the css folder is inside your html folder, this should work. Note the leading slash in the path. That means that the path is relative to the root html directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.