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();

  • 相关阅读:
    Collection与Collections的区别
    Java容器基础概况
    IO与NIO的区别
    BIO、NIO、AIO的区别
    Java中的IO流
    Java中的抽象类
    String常用方法解析
    字符串反转
    vue路由传参
    flask框架(八)—自定义命令flask-script、多app应用、wtforms表单验证、SQLAIchemy
  • 原文地址:https://www.cnblogs.com/gbyukg/p/2444997.html
Copyright © 2011-2022 走看看