1

I can not append image or css file in my zend project.I put my css file into

project/public/css/style.css . 

My page can not include this css file. When I copy css file url redirect to my homepage. however if i type anything in end of my url address redirect to my home page.

For example when I go to /project.com/asdsadasda I do not get any errors and it renders the homepage but with wrong address.

1
  • What URL are you going to to be redirected to the homepage? Also please edit your question to include the contents of public/.htaccess Commented Feb 26, 2013 at 9:29

2 Answers 2

1

In your bootstrap.php file add this:

protected function _initViewHelpers()
   {
      $this->bootstrap('layout');
      $layout = $this->getResource('layout');
      $view = $layout->getView();
      $view->headLink()->setStylesheet('/css/style.css');  // your CSS file
   }

And in your layout.phtml add this lines in top:

<head>
<?php echo $this->headMeta() ?>
<?php echo $this->headTitle() ?>
<?php echo $this->headLink()?> </head>

EDIT.

If you don't know how to turn on layout support in Zend Framework read this tutorial: http://akrabat.com/zend-framework/simple-zend_layout-example/

Sign up to request clarification or add additional context in comments.

3 Comments

my main problem is no address doesn't work if i type any thing in my url doesn't get any error
I created error contoller. And zend FW think css folder is controller.how can i fix this problem:
Bootstrap should be used only for global css-es, not any files that are specific for a controller.
0

To effectively use your css file, you need to create a Layout. let says Layout.phtml is your layout then the head can reference you css file this way :

<html>

<head>
<?php echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/style.css'); ?>
....
</head>

....

good chance

1 Comment

I created layout: <?php echo $this->docType(); ?> <html> <head> <meta charset="utf-8"> <? echo $this->headLink()->appendStylesheet('/css/style.css') ?> </head> <body>

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.