Zend framework: Accessing request, response & router object from anywhere

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.