在MVC之外使用Zend Framework处理输入 [英] Handling Input with Zend Framework outside MVC

查看:79
本文介绍了在MVC之外使用Zend Framework处理输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在经典的Zend Framework MVC设置中,似乎可以从模型/视图/控制器实例内部访问通用的_request对象,如

In a classic Zend Framework MVC setup, there seems to be access to a generic _request object from within the model/view/controller instance as outlined here:

$this->_request->getPost('variablename');

该请求对象在非MVC设置中是否也可以使用?

is this request object somehow available in a non-MVC setup as well?

如果是:我将如何初始化和访问它?

If yes: how would I initialize and access it?

推荐答案

我不会使用 API 公开了许多完全针对在ZF的MVC中使用的方法,这些方法是 all 子类型所继承的.

I would not use the Zend_Controller_Request_* objects outside ZF's MVC structure (even if possible). You can see by the class name already that it belongs to the controller package and it's API exposes a number of methods that are completely targeted at being used within ZF's MVC and these are inherited by all subtypes.

使用ZF的MVC可以,但是对于超出此范围的使用,请求对象会做太多事情. Request对象的想法是封装当前的Request环境,并可能将其与Superglobal分离(ZF没有这样做.它只是位于顶部).我认为,有关模块,控制器和操作的所有其他多余内容均不应包含在其中.在ZF中这才有意义.

That's okay when using ZF's MVC, but for usage outside of that the Request Objects do too much. The idea of a Request object is to encapsulate and maybe decouple the current Request environment from the Superglobals (which ZF doesn't. It just sits on top). All that extra stuff about modules, controllers and actions shouldn't be part of it in my opinion. It makes only sense in ZF.

编写一个Request对象并不困难,因此我相信您可以轻松地提出一个更轻量级的版本.以下是一些基本示例:

Writing a Request object isn't difficult, so I'm sure you can easily come up with a more lightweight version. Here is some basic examples:

  • http://www.phpdesignpatterns.de/auflage-2/downloads/code/PHP-Design-Pattern-Kapitel-8.zip
  • http://github.com/sebastianbergmann/php-mvc-ukernel/blob/master/Request.php
  • http://github.com/spriebsch/MVC/blob/master/src/Request.php

最后还是您的选择.

这篇关于在MVC之外使用Zend Framework处理输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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