下面的方法如何工作?
$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/