Zend框架默认的MVC实现 [英] Zend framework default MVC implementation

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

问题描述

我已经使用Zend Framework已有一段时间了.自从阅读大量文档后开始我就遇到了一个问题,我想知道为什么所有示例都没有提到它.

I have been using Zend Framework for a while now. I am having an issue since de beginning an after reading a lot of documentation i was wondering why all exemples dont mention it.

如果我是对的,那么MVC设计模式倾向于使用单个入口点与应用程序进行交互.借助Zend,其公用文件夹中的index.php文件.

If I am right, the MVC design pattern favorise a single entry point to interract with the application. With Zend its the index.php file in the public folder.

我尝试将这种方式与Zend提供的默认(v 1.09).htaccess一起使用:

I tried to use this way with the default (v 1.09) .htaccess that Zend provides :

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

和默认的index.php文件:

and the default index.php file :

// 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个服务器错误,而是能够使页面正常加载.

But so far I have been unable to use the single entry point, I had to duplicate the index file and give it the name of the related controller. This way instead of getting a 500 server error, I was able to get the page to load normally.

所以,我的问题是:让我的应用程序正常工作会出错吗?这是正常的做事方式吗?

So, my question is : What am I getting wrong to get my application to work? Is it the normal way of doing things?

谢谢

编辑@ 13h55

我已将服务器重新配置为通过虚拟主机(而不是别名)访问zend安装,看来这是错误所在.

I have reconfigured my server to access the zend installation through a virtual host instead of an alias and it seems that that was the error.

我是从一个别名开始的:

I went from an alias looking like :

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>

对于如下所示的虚拟主机:

To a virtual host looking like :

<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中编辑文件主机,以在文件中添加examen.elul.local

Since it runs locally, i also had to edit the file hosts in C:\WINDOWS\system32\drivers\etc to add examen.elul.local in the file

127.0.0.1       examen.elul.local

推荐答案

如果您更喜欢使用别名而不是虚拟主机,则可能要使用RewriteBase,或者可以将基本URL放在前控制器的前面:

If you prefer using an alias instead of a virtual host, you might want to use the RewriteBase or you may prepend the base url to the frontcontroller:

RewriteBase /elul/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /elul/index.php [NC,L]

也应该工作...虽然我使用了这个:

should work too... I use this one though:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /project_name/index.php

这是一条比较简单的规则,但是我不确定它是否真的影响性能或是否涵盖了所有可能性.

It's a simpler rule but I'm not sure if it really affects the performance or covers all the possibilities.

这篇关于Zend框架默认的MVC实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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