【发布时间】:2010-11-08 17:05:28
【问题描述】:
我使用 Zend Framework 已经有一段时间了。自从开始阅读大量文档后,我遇到了一个问题,我想知道为什么所有示例都没有提及它。
如果我是对的,MVC 设计模式偏爱单个入口点来与应用程序交互。使用 Zend,它的 index.php 文件位于 public 文件夹中。
我尝试在 Zend 提供的默认 (v 1.09) .htaccess 中使用这种方式:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
以及默认的 index.php 文件:
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
但到目前为止,我一直无法使用单一入口点,我不得不复制索引文件并为其指定相关控制器的名称。这样,我就可以正常加载页面,而不是收到 500 服务器错误。
所以,我的问题是:让我的应用程序正常工作我做错了什么?这是正常的做事方式吗?
谢谢
编辑@ 13h55
我已重新配置我的服务器以通过虚拟主机而不是别名访问 zend 安装,这似乎是错误。
我的别名看起来像:
Alias /elul/ "c:\wamp\www\elul\trunk\elul\public/"
<Directory "c:\wamp\www\elul\trunk\elul\public/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
到一个看起来像这样的虚拟主机:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "C:\wamp\www\examen_fle\trunk\examen_fle\public"
ServerName examen.elul.local
ErrorLog "logs/your_own-error.log"
CustomLog "logs/your_own-access.log" common
<directory "C:\wamp\www\examen_fle\trunk\examen_fle\public">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
由于它在本地运行,我还必须编辑 C:\WINDOWS\system32\drivers\etc 中的文件 hosts 以在文件中添加examen.elul.local
127.0.0.1 examen.elul.local
【问题讨论】:
-
这可能很简单,因为您的 http 服务器没有解析 .htaccess 文件。
AllowOverrideApache 设置是否正确? -
您的
mod_rewrite设置是否正确?a2enmod rewrite启用它 + apache 重启。 -
到目前为止 mod_rewrite 正在工作(如果我禁用它,我会收到一个未找到的错误)以及是否有一个指向我的公用文件夹的别名。我会用一个虚拟主机试试这个,看看它是否改变了什么。
标签: model-view-controller zend-framework