Zend框架中的一个子文件夹 [英] Zend Framework in a subfolder

查看:163
本文介绍了Zend框架中的一个子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装在一个子文件夹中的Zend Framework应用程序,这样的事情:

I have installed a Zend Framework application in a subfolder, something like this:

www.mydomain.com/temp/zend-application/

现在的问题是所有的样式表,JavaScript文件和所有链接使用相对路径,如:

Now the problem is all stylesheets, javascript files and also all links use relative paths, such as:

/css/styles.css
/js/jquery.js
/controller/action

和这些进入的主要领域是这样的:

And these go to the main domain like this:

www.mydomain.com/css/styles.css
www.mydomain.com/js/jquery.js
www.mydomain.com/controller/action

那么如何让它在该子文件夹的工作?

So how to make it work in that subfolder?

我的.htacces文件看起来像现在这样:

My .htacces file looks like this now:

RewriteEngine On

# Exclude some directories from URI rewriting
#RewriteRule ^(dir1|dir2|dir3) - [L]

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

编辑:我已使用setBaseUrl的前端控制器()方法解决了这个问题。现在的问题是如何编辑我的.htaccess文件。

I have solved the problem by using setBaseUrl() method of front controller. Now the problem is how to edit my .htaccess file.

推荐答案

最好的解决办法是<一个href="http://framework.zend.com/manual/en/zend.controller.request.html#zend.controller.request.http.baseurl"相对=nofollow>在应用程序中设置的baseUrl 。如果设置了的RewriteBase 在你的.htaccess。路由器和其他组件有此设置的知识,并能产生相应的链接。

The best solution would be to set a BaseUrl in your application. This should be detected automatically if you set a RewriteBase in your .htaccess. The router and other components have a knowledge of this setting and can generate appropriate links.

有一个视图助手这使得联资产更容易。

There's a view helper which makes linking to assets easier.

另外,您可以修复这些链接在文档头部的标签。

Alternatively you can fix those links with a tag in the document head.

<html>
<head>
<base href="http://www.mydomain.com/temp/zend-application/">
</head>

延伸阅读在 http://www.w3schools.com/TAGS/tag%5Fbase .asp的

这篇关于Zend框架中的一个子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆