Zend Framework Reference

Zend Framework use HTML in Zend Form Label

To use HTML in a Zend Framework Form standard label you will first have to set the escape option in the relevant Label decorator to false. Like so:

Zend Framework Use Zend mail with Zend view

Here´s an example combining Zend mail and Zend View for easy mail templating.

Zend Framework set selected Zend Form select

To set the selected value of a select element in a Zend Form object you need to use it's setValue method:

Zend Framework using MySQL NOW() expression in Zend db insert statement

To insert the current date / time MySQL offers the convenient NOW() function that can be used in an insert query. To use this same function inside a Zend framework db adapter insert statement you can use the following syntax:

Zend Framework Change layout file from controller action

To choose another layout file inside your controller all you need to do is invoke the layout helper like so:

Zend Framework access view inside custom view helper

To access the view instance from your homemade view helper you just need to create a setView method and view property. This will be automatically called upon instantiation, setting the view variable to point at the view instance.

Example:

Zend Framework Simple Zend Router example

The default routing setup for Zend is ':module/:controller/:action/*'

Zend Framework Get baseurl inside a Zend Form descendant class

Often when using the Zend Form components it's convenient to Extend the Zend Form class. To set the action to of the form it will be necessary to access the base url helper method of the view object.

Because you don't have direct access to the view object from inside a Zend Form object, you have to do something like this:

Zend Framework Get Zend Db Adapter instance

If you're using Zend Framework 1.8+, and created your project with the command line tool, then it's as simple as registering your database settings in your application.ini config file.

Zend Framework Access view values from partialLoop

Partials are handy because they allow you to dissect html code and template logic into smaller reusable bits. PartialLoops allow you to loop through objects and arrays in an efficient manner and in a seperate variable scope.

Sometimes it is neccessary to access variables and their values from the view object's scope that the partial was called from.

This can be done quite easily from the by calling the partialLoop() or partial() (or another view helper's) method from the partial template and then accessing the view object from that.

Zend Framework Zend db examine SQL query

You can use Zend_db_profiler to capture and examine the sql queries or statements that Zend db adapter forms and executes. example:

Zend Framework Retrieve request params

To get the request parameters in a Zend framework controller action you can use:

Zend Framework Register plugins in ZF application.ini

To register frontController plugins in the ZF (1.8 and higher) application.ini file you can use the following syntax:

Zend Framework Set constants in ZF application ini file

To be able to set application wide constants inside the application ini file you can define a function as follows in the bootstrap class:

Zend Framework Change view script in ZF controller action

To change from the default view script (based on the action's name) and dynamically pick another view script to render you can use the following code:

Zend Framework Quick setup of navigation menu on every page

Just add the following to layout.phtml (or the file of your layout template is in)

Zend Framework Disable layout and viewRenderer in controller

To disable the layout and the viewrenderer on the fly inside a controller you can use the following lines :

Zend Framework Set response segment in controller actions

The default response segment your controllers action are outputting to is 'content'.

To change/set what response segment is written to inside your controller actions you can use the setResponseSegment method of the viewrenderer helper:

[x]