我正在尝试在我的 zend 应用程序中添加一个 css 文件layout.php
问题是它驻留在
/application/media/css/style.css
当我这样做时
<?php echo $this->headLink()->appendStylesheet('/media/css/style.css') ?>
它生成路径如下
appname/public/media/css/style.css
我需要生成路径
的地方,例如appname/application/media/css/style.css
我怎样才能告诉 Zend 在布局中的位置查找 CSS 文件.php
我已经解决了这个问题。总是很简单。:D我添加了
<link rel="stylesheet" href="css/site.css" type="text/css" media="screen, projection">
在头标签中。css 文件夹位于公共文件夹中。
谢谢欧姆
应用程序目录中的所有内容都无法通过Web服务器访问,您必须将文件移动到公共目录或设置指向它的符号链接。
只是为了完成所有答案,将您的 CSS、JS、字体和所有其他媒体放在"应用程序"文件夹中是不"正确的"。 "公共"文件夹就是为此而存在的。然后,要从所有URL中删除"/public",只需在.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]
在您的索引中.php
<?php
define('RUNNING_FROM_ROOT', true);
include 'public/index.php';
然后你可以用它来附加你的样式
<?php echo $this->headLink()->appendStylesheet('/public/media/css/style.css') ?>
希望对您有所帮助。
您应该使用以下代码:
<link rel="stylesheet" type="text/css" media="screen" href="<?=$this->baseUrl();?>/yourpathtocss" />
我认为正确的方法是从 layout.phtml 执行此操作,如下所示
<?php echo $this->headLink()->appendStylesheet('/css/site.css') ?>
这里的"TestZend"是项目名称
<?php echo $this->headLink()->appendStylesheet('/TestZend/public/css/bootstrap.css'); ?>
只需在布局部分添加此代码片段,以确保在 yourProjectFoder/public/media/css/style.css
中创建 MEDIA 文件夹
<head>
// some code here...
<?= $this->headLink()
//added from the new template
->prependStylesheet($this->basePath('media/css/style.css'))
?>
// some other code here
</head>