将CSS文件添加到布局Zend Framework

问题描述 投票:2回答:7

我正在尝试在我的zend应用程序layout.php中添加一个css文件,它存在的问题是什么

/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文件

zend-framework
7个回答
3
投票

应用程序目录中的所有内容都无法通过您的Web服务器访问,您必须将文件移动到公共目录或设置symlink


4
投票

我已经解决了这个问题。总是很简单。 :D我补充道

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

在头标记。并且css文件夹位于公共文件夹中。

谢谢哦


1
投票

只是为了完成所有答案,不是“正确”将你的CSS,JS,字体和所有其他媒体放在'application'文件夹中。 'public'文件夹就是为此而存在的。然后,要从您的所有网址中删除“/ 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]

在你的index.php中

<?php

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

然后你可以使用它来追加你的风格

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

希望能帮助到你。


0
投票

您应该使用此代码:

<link rel="stylesheet" type="text/css" media="screen" href="<?=$this->baseUrl();?>/yourpathtocss" />

0
投票

我认为正确的方法是从layout.phtml执行此操作,如下所示

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


0
投票

这里'TestZend'是项目名称

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

0
投票

只需在布局部分添加此代码段,以确保在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>
© www.soinside.com 2019 - 2024. All rights reserved.