我是Zend Framework的新手。我想知道如何在共享主机上实现zend框架。由于zend框架文件夹结构 所有视图文件都放在“公共”文件夹中。Zend Framework共享主机
假设
“/”是我主要的根文件夹和公共就像 “/公众”
,使URL成为“http://site/public/ .. .bla喇嘛......”
这是正确的吗?
还是还有其他方法吗?
我没有任何权限来创建虚拟主机。
那该怎么办?
我希望你能理解我的问题。如果没有,请问我。
谢谢!
我是Zend Framework的新手。我想知道如何在共享主机上实现zend框架。由于zend框架文件夹结构 所有视图文件都放在“公共”文件夹中。Zend Framework共享主机
假设
“/”是我主要的根文件夹和公共就像 “/公众”
,使URL成为“http://site/public/ .. .bla喇嘛......”
这是正确的吗?
还是还有其他方法吗?
我没有任何权限来创建虚拟主机。
那该怎么办?
我希望你能理解我的问题。如果没有,请问我。
谢谢!
我认为最好的方法是删除从(Zend Framework的目录结构)公共目录中的.htaccess,并把它与下面的内容到你的“根”目录:
RewriteEngine On
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]
事实上,它不是在共享主机上运行Zend Framework应用程序的最佳理想选择。我真的会推荐一个虚拟私人主机(VPS)。 Zend Framework和已经安装并定期更新的其他框架有非常好的和便宜的主机。我在servergrove,到目前为止一直很棒!
但这并不意味着你不能使它在共享主机上工作。你只需要使用.htacess。将公用文件夹的内容放入webroot中,并在bootstrap.php中调整路径,确保所有其他文件夹不能直接访问,并使用通常的ZF方法将所有内容路由到index.php。
关于我自己实现这种方法的详细信息:http://bit.ly/btQGbh – 2010-05-08 17:22:16
我建议最简单的方法是:以index.php位于根目录的方式开发应用程序(甚至更好 - 总是在index.php中定义PUBLIC_PATH - dirname(__FILE__);
并使链接相对于此常量)。与应用程序和库文件夹一起。使用.htaccess中的deny from all
可以轻松地使其无法访问。
当你的公众不公开时,PUBLIC_PATH常量也有帮助。 (public html或/ public html/www(在我的情况下))
我一直处于相同的情况,并已将zend库放在公共文件夹下,如'src' - 并使用.htaccess Deny所有。你将不得不玩弄几条路径,但它工作正常。
包含该.htacces文件的基本路径下(即/../public):
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]
并留下那是publc目录,它是下的.htaccess。
所以你会有2。htaccess文件,一个在公共目录下(来自Zend Framework文档的普通文件),另一个在你的基本路径下(我在上面发布的)。
。 。 。 Magento如何使用Zend框架?我使用的是XAMPP,并且我在本地安装了Magento,而无需修改php.ini,http.conf和虚拟主机。
您应该将项目的公用文件夹放在主机的www文件夹中,这样您的地址将成为yourdomain.com/。 您的源代码文件夹如库,应用程序...应与www文件夹放在同一层,而不是放在它之内。这种方法将促进您的网站的安全
ArneRie的答案不适合我,我最终结束了使用Lorenzo Albertons solution。希望这有助于他人获得更快的解决方案。
RewriteEngine On
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]
其实我已经搜索了一下,发现很多答案(其中大部分在这里SO),但他们没有为我工作。所以,我终于找到了解决办法 - 的.htaccess的根目录:
RewriteEngine on
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php
这一个从http://framework.zend.com/wiki/display/ZFDEV/Configuring+Your+URL+Rewriter 和index.php文件的根目录:
<?php
define('RUNNING_FROM_ROOT', true);
include 'public/index.php';
?>
这一个从http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/ 它为我的作品即使有其他项目目录在根文件夹 - 如论坛等。 认为它可能是有用的人:)
而且Rob Allen wrote a good solution
我使用Zend框架2,它为我工作。 Alghough我还没有做过“参考公共文件”从上面的链接。
我只是改变代码在我layout.phtml来自:
$basePath = $this->basePath();
到:
$basePath = $this->basePath();
if (defined('RUNNING_FROM_ROOT')) {
$basePath .= 'public/';
}
最近我遇到了这个问题,并通过这个线程我能找到一个解决方案。我正在使用zf2。所以我所要做的就是在一个目录中有zend相关的文件,我们可以命名为src
。该目录将驻留在公共或根目录下(如/www
)
在“SRC”目录创建一个.htaccess文件,并添加来自所有指令拒绝。
在索引文件中,通过做工作目录更改为src
文件夹下面的:
define('SRC_ROOT', 'src');
chdir(SRC_ROOT);
...你是好去!
设置虚拟主机通常在httpd.conf或extra/httpd-vhosts.conf中完成。如果您使用的是httpd-vhosts。conf,确保这个文件包含在你的主httpd.conf文件中。一些Linux发行版(例如:Ubuntu)打包Apache,以便配置文件存储在/ etc/apache2中,并为启用/ etc/apache2/sites-enabled的文件夹中的每个虚拟主机创建一个文件。在这种情况下,您可以将下面的虚拟主机块放入文件/ etc/apache2/sites-enabled/zf2-tutorial中。
确保了NameVirtualHost被定义并设置为“*:80”或类似的,然后定义沿着这些线路虚拟主机:
Setting up the virtual host is usually done within httpd.conf or extra/httpd-vhosts.conf. If you are using httpd-vhosts.conf, ensure that this file is included by your main httpd.conf file. Some Linux distributions (ex: Ubuntu) package Apache so that configuration files are stored in /etc/apache2 and create one file per virtual host inside folder /etc/apache2/sites-enabled. In this case, you would place the virtual host block below into the file /etc/apache2/sites-enabled/zf2-tutorial.
Ensure that NameVirtualHost is defined and set to “*:80” or similar, and then define a virtual host along these lines:
<VirtualHost *:80>
ServerName zf2-tutorial.localhost
DocumentRoot /path/to/zf2-tutorial/public
SetEnv APPLICATION_ENV "development"
<Directory /path/to/zf2-tutorial/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Make sure that you update your /etc/hosts or c:\windows\system32\drivers\etc\hosts file so that zf2-tutorial.localhost is mapped to 127.0.0.1.
确保您更新/ etc/hosts或c:\ windows \ system32 \ drivers \ etc \ hosts文件,以便将zf2-tutorial.localhost映射到127.0.0.1。
嗨 - 只是想知道你能发现我在这个帖子底部发布的细节有什么问题吗? – emeraldjava 2009-09-03 12:30:27
可能的n00b问题:这对ZF路由有什么影响?也就是说,“/ public”前缀不会成为ZF看到的url的一部分(我猜想通过$ request对象)?因此,现在所有的ZF路线都需要“/公众”意识吗?这将是不可取的,不是吗? – 2009-12-10 07:10:19
在哪里放置环境的设置? – JellyBelly 2012-04-19 09:04:35