zoukankan      html  css  js  c++  java
  • Zend Framework: Accessing Request, Response & Router Object from anywhere

    In Zend Framework you can access the current request object from anywhere outside the current controller, for example inside your own base classes. To do so you obtain the singleton instance of the Front Controller Object and access the current request object registered with it.

    Here is how you do it:

    Zend_Controller_Front::getInstance()->getRequest();

    Once you have the access to the Request object, you may access all other methods and objects registered to it. For example you can get the current module name as shown below

    Zend_Controller_Front::getInstance()->getRequest()->getModuleName();

    Above code snippet is especially useful when you are trying to detect the current request object outside the current controller class.

    Accessing the instance of the Front Controller as shown above, gives you the way to access even other objects registered with it like the Response object or the Router Obect, which can be inspected or manipulated further. The below code gives reference to the current Response object.

    Zend_Controller_Front::getInstance()->getResponse();

    To access the Router object you may use the following code:

    Zend_Controller_Front::getInstance()->getRouter();

  • 相关阅读:
    JSP(工作原理,组成部分,指令标签,动作标签,隐式对象)
    会话技术cookie与session
    上下文对象-请求对象-响应对象(ServletContext
    反射
    Servlet
    Tomcat服务器
    Http协议
    客户端与服务器
    Oracle虚拟机 与 windows配置
    SQL语句简单整理
  • 原文地址:https://www.cnblogs.com/gbyukg/p/2444997.html
Copyright © 2011-2022 走看看