Posted: February 23rd, 2011

Zend Framework, Subforms and organization

Category: PLAIN, technical
Tags: , , ,

Recently I have been tasked to organize some form fields into nice columns. Normally you would use display groups. Since you really can not nest display groups, subforms were the answer. I have split my elements into 2 different sections and w/in these sections are basic incarnations of forms at the basic level ( utilizing the init() and extending Zend_Form() ). w/in each form I have many elements and display groups.

so in a nut shell here’s what i have,

first off you create "empty" subforms

$left = new Zend_Form_SubForm();    

then you add the subforms you want inside of this "subform"

$left->setSubForms(array(
   ‘sub1′  => $sub1,
   ‘sub2′  => $sub2
));

you do the same thing for the other subform you want to add decorators to.

$right = new Zend_Form_SubForm();    

$right->setSubForms(array(
   ‘sub3′  => $sub3,
   ‘sub4′  => $sub4
));

then to your original form you add these new "$left" and "$right" subforms

$this->setSubForms(array(
   ‘left’  => $left,
   ‘right’ => $right
));

you can then apply decorators to the "$left" and "$right" subforms as you see fit.

since i want to drop the fieldsets that encapsulate the elements inside mine looks like this, you do the same to the other one.

    $left->setDecorators(array(
        ‘FormElements’,
        array(‘HtmlTag’, array(‘tag’ => ‘div’)),
        ));
Posted: February 2nd, 2011

Zend_Navigation and Routes

Category: technical
Tags: ,

now here’s my take on the Zend_Navigation and routes. Normally you can set a resource class to do this, but I rather do it in the bootstrap. kinda the same thing in my opinion, i decided not to use a xml config but a ini config type, this way you don’t have to worry if your tags are closed properly. if it works for you awesome.


protected function _initNavigation() {
// set up navigation
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/navigation.ini','navi');
$navigation = new Zend_Navigation($config);
$view->navigation($navigation);
return $view;
}


protected function _initRoutes() {
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/navigation.ini', 'routes');
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$router->addConfig($config,'routes');
$front->setRouter($router);
return $router;
}

sample ini file

;put routes here.
[routes]
routes.dashboard.route = "/dashboard"
routes.dashboard.defaults.controller = index
routes.dashboard.defaults.action = dashboard


;navigation
[navi]
dashboard.route = "dashboard"
dashboard.controller = index
dashboard.action = dashboard
dashboard.label = dashboard
dashboard.class = dashboard

Posted: June 12th, 2010

Zend Framework redirect within plugin

Category: technical
Tags: , , ,

if you ever need to redirect w/in a plugin

$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper(‘redirector’);
$redirector->gotoUrl(‘url’);