php - Zend Framework - 在oop原理中,方法 '$this->getRequest()->getPost()'如何工作?

标签 php oop zend-framework

下面的方法如何工作?

$this->getRequest()->getPost();

Zend_Controller_Request_Abstract 中没有方法getPost(),但它是如何工作的呢?在OOP原则中,方法getPost()应该出现在Zend_Controller_Request_Abstract中。

如果没有直接实例,Zend 如何在 Zend_Controller_Request_Http 类中拉取 getPost()

谢谢。

最佳答案

Zend 将首先将您的所有请求发送到 FrontController,它位于 Zend/Controller/Front.php。 FrontController 会将 Http 请求注入(inject) Controller ,这里是它发生的代码

    /**
     * Instantiate default request object (HTTP version) if none provided
     */
    if (null !== $request) {
        $this->setRequest($request);
    } elseif ((null === $request) && (null === ($request = $this->getRequest()))) {
        require_once 'Zend/Controller/Request/Http.php';
        $request = new Zend_Controller_Request_Http();
        $this->setRequest($request);
    }

The purpose of frontcontroller is to initialize the request environment, route the incoming request, and then dispatch any discovered actions; it aggregates any responses and returns them when the process is complete.

关于 FrontController 的更多信息 here

进一步回答您的问题

/**
 * Return the Request object
 *
 * @return Zend_Controller_Request_Abstract
 */
public function getRequest()
{
    return $this->_request;
}

这就是你在 Zend/Controller/Action.php 中要做的——这里的注释说 Zend_Controller_Request_Abstract 'is-a' 返回类型。我突出显示 'is-a' 因为它可以返回任何 'is-a' Zend_Controller_Request_Abstract 的类。有关 is-a 的更多信息,请查看此 wikipedia

"In knowledge representation, object-oriented programming and design, is-a or is_a or is a (subsumption) is a relationship where one class D is a subclass of another class B (and so B is a superclass of D)."

关于php - Zend Framework - 在oop原理中,方法 '$this->getRequest()->getPost()'如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10029595/

相关文章:

php - Ruby 相当于 PHP 的 $this

java - Java中动态多态和静态多态有什么区别?

zend-framework - ZF3 : SharedEventManager injection in EventManager

javascript - PHP 错误此站点需要启用 JavaScript

php - 如何使用 .htaccess 加载默认索引文件以获取 url 中的可变目录结构

php - 在每次字符更改时将空格插入字符串

java - 关于带焊接/CDI 的 LCOM4 的问题?

从数据库输入到联系表的php mysql数据

php - 这个 zend 更新语句的流程是什么

php - 如何使用 Zend_Db_Adapter 在每次调用 "query"时运行多个 SQL 查询?