0

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.

3 Answers 3

4

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" />
Sign up to request clarification or add additional context in comments.

9 Comments

the code i used: <? $this->headlink()->appendStylesheet('css/screen.css', 'screen,projection'); ?> <? $this->headlink()->appendStylesheet('css/ie.css', 'screen,projection', 'IE'); ?> <? $this->headlink()->appendStylesheet('css/print.css', 'print'); ?> <?= $this->headlink(); ?>
Just add the baseUrl I gave you to the url you have: ... $this->baseUrl().'/css/screen.css'......
Tried it and i got Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'BaseUrl' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/;./views\helpers/;./application/views\helpers/' in
Of course, You must create the class (see code above) as a view Helper, in the helper directory and name it according to what ZF expects.
copied the Zend_View_Helper_BaseUrl and saved the file as Zend_View_Helper_BaseUrl.php in helpers folder under views folder, but i still got the error: Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'BaseUrl' was not found in the registry;
|
1

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.

3 Comments

thanks for the response. i will give you more info on my directory layout: webroot/ library/ application/ controllers/ models/ views/ scripts/ filters/ helpers/ layouts/ css/ index.php .htaccess thats the directory structure.
sorry, my last comment didnt show the way i wanted it, but i can explain. my application, library, and css folder is in my webroot root folder. I tried what you suggested but its still not working.
index.php is not in your webroot? It needs to be.
0

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"

Comments

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.