views:

80

answers:

2

I just moved from ZF 1.6 to ZF 1.9, there is a lot of changes since i started with it, and i've to refactor some of my libraries.

In order to don't forget anything, and to have a great generic library where i can pick up elements, i was wondering what are your most used generic classes you had to write for ZF ?

I'm thinking for example about the classic baseUrl helper, or some implentation of the Domain Model / Active Record / Collection.

It'll be a great help for me (and maybe for some other) to prepare some tools which i could forget in the future !

thanks

+1  A: 

mmm generic classes? Well I use a Auth adapter, ACL, a Module Controller, and a DataGrid Class, those are my top of the list classes that I use a lot on my projects, and they are generic enough that work perfect on all of the ZF versions I have tested.

Chris
A: 

The things I find myself using over and over again are some action helpers. One that loads and caches Models, another that validates parameters, another that manages error warning and info messages (similar to flashMessenger except that it works whether you _forward or redirect or access them inside the current query). Also some customised form controls (like a Save and Cancel button that appear beside each other with no Label), and some view Helpers that return an a href if the user has ACL permissions to visit the module/view/action. These are generic and live in a shared include directory used by all projects.

I had a whole bunch of generic classes (like an extension of Zend_Controller_Action) but as the framework has matured, these have been needed less and less often because the behaviours can be shifted into smaller more general helpers and utilities that can be loaded on demand. [I've been using ZF since 0.9]

The Model helper is below

//-------------------------------------------------------------------------
/*! \brief loads and caches models

    usage in an Action controller: eg
    $users = $this->_helper->model( 'User' );
    loads MODEL_PATH . User.php

    Idea stolen from
    http://fedecarg.com/wiki/Module-specific_Models
*/
class LSS_Controller_Action_Helper_Model extends Zend_Controller_Action_Helper_Abstract
{
    const PREFIX = 'MODEL_';

    //-------------------------------------------------------------------------
    /*! \brief return a global instance of the specified model.
        Uses Zend_registry to store a cached instance of the model so we don't have to load it
        in each function. 
        You can use sub directories by passing in the class name eg Customer_Session
        \param $type string type of value to return
        \return model instance
    */
    function direct( $name )
    {
        $regName = self::PREFIX . $name;
        if (Zend_Registry::isRegistered( $regName )) return Zend_Registry::get( $regName );

        require_once( MODEL_PATH . str_replace( '_', '/', $name ) . '.php' );
        $instance = new $name;
        Zend_Registry::set( $regName, $instance );
        return $instance;
    }
}
Steve