Skip Navigation LinksHome > Categories > Code from a Category

Create a simple access to resources from ZF controller.

User Name: serfcompany
Name: Serf
Contact Me:
Home Page:
php,mysql,javascript,html,css. Preferable working with Zend Framework. Good know javascript. I worked with various, javascript frameworks such as(jquery, YUI3, extjs, sencha touch). [More]
Viewed Times: 1897
Add Date: 06/15/2012
It would be nice to have access to downloadable resources to bootstrap the application of the controllers. For example, I would like to access the "DB" resource from the controller to read $ this-> db;

To do this, write Action Helper, which will load some resources in the application controller:

and initialize it to the bootstrap:

The code above will create links to resources: db, layout and navigation. This means that now you can get them direct access from the controller.

This decision leads to some simplification - there is no need of bootstrap pulling the object initialization, and then pull the resource.
However, this solution has several problems: How do we know what resources were associated with the controller? How can we control it?
Hence, it follows the decision to create a pool of resources needed for the controller.

The new Action Helper load resources will now look like this:

You still have to register it in the bootstrap, but now without a list of resources:

Instead, the desired list Resources of you now specify in the controller:

This creates a more clear understanding of what resources are needed the controller and each controller receives exactly the resources that it will use.

Another improvement that we can add to the resource loader - is if the dependent resource was not found, an exception is thrown:

This gives us the understanding and track luchshenie dependent resources. Resources are defined by the object that needs them, but lacking resources will cause an exception.

One potential improvement that can be done is an indication of a list of resources are automatically downloaded to each controller. To accomplish this, you need to merge the list will default to the resources defined in kontrollrere. This task I leave to my readers.

Area Action Helpers is poorly investigated ZF users. I hope this post will show how much the Action Helpers can automate repetitive and common tasks.

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.