In this tutorial I am going to describe a typical scenario where we use Zend View Helpers to do some common view task throughout the application. Moreover we want this helper to be located in some common place/directory from where it is accessible to any module in an application.
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:
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
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.
To access the Router object you may use the following code: