2012-04-07 83 views
1

我想添加一個CSS文件在我的Zend應用layout.php的問題是,它駐留在添加CSS文件佈局Zend框架

/application/media/css/style.css

當我這樣做

<?php echo $this->headLink()->appendStylesheet('/media/css/style.css') ?> 

它產生像

路徑

APPNAME /公/媒體/ CSS/style.css中

那裏,因爲我需要生成像

應用程序名稱/應用/媒體/ CSS/style.css的路徑

我該如何告訴zend在layout.php的特定位置尋找css文件

回答

3

應用程序目錄中的所有內容都無法通過您的Web服務器訪問, d要麼必須將文件移動到公共目錄,要麼將它設置爲symlink

3

我已經解決了這個問題。總是很簡單。 :D 我加了

<link rel="stylesheet" href="css/site.css" type="text/css" media="screen, projection"> 

in head tag。並且css文件夾位於公共文件夾中。

感謝 歐姆

+0

謝謝@歐姆,但我想這是同樣的解決方案@nav提供了 – 2012-04-10 17:57:16

0

您應使用此代碼:

​​
0

我認爲正確的做法是從layout.phtml做法如下

<?php echo $this->headLink()->appendStylesheet('/css/site.css') ?>

0

這裏「 TestZend'是項目名稱

<?php echo $this->headLink()->appendStylesheet('/TestZend/public/css/bootstrap.css'); ?> 
1

只是爲了完成所有的答案,是不是「正確」把你的CSS,JS,字體和所有其他媒體放在'應用程序'文件夾中。 '公共'文件夾就在那裏。 然後,從您的所有網址中刪除 '/公衆',只是做一個簡單的改變你的的.htaccess

RewriteEngine On 
RewriteBase/# you could put some subfolder, if you need 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 

而在你的index.php

<?php 

define('RUNNING_FROM_ROOT', true); 
include 'public/index.php'; 

然後你可以用它來追加你的風格

<?php echo $this->headLink()->appendStylesheet('/public/media/css/style.css') ?> 

希望它有幫助。

+0

正是我需要的,謝謝!不知道爲什麼這不被接受爲答案。 – 2016-06-12 13:57:35