I’ve been fervently coding Blitzaroo the passed week and I ran into a rather annoying issue when using AJAX with the Zend Framework and Dojo. Take, for example, using AjaxContext to load content for a dijit.layout.TabContainer that houses several dijit.layout.ContentPane(s).
1 2 3 4 5 6 | $ajaxContext = $this ->_helper->getHelper( 'AjaxContext' ); $ajaxContext ->addActionContexts( array ( 'overview' => 'html' , 'events' => 'html' , 'members' => 'html' , 'recruits' => 'html' ))->initContext(); |
Now then, when the getHref() from a ContentPane is called they load the Ajax data which, in this case, happens to be a dojox.grid.DataGrid. The grid renders just fine without Ajax but when Ajax is used ZF fails to load the proper Stylesheets which need to be loaded manually. I thought, no big deal, I’ll just hit up $this->dojo()->{some method to spit out stylesheets} and to my dismay found that the method is protected. Why? I’m not quite sure. I went ahead and wrote a view helper to fix the problem which is merely a copy/paste of the _renderStylesheet() method but without requiring the Dojo container object. If there is another way around the issue I’m all ears!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | class My_View_Helper_DojoStylesheets extends Zend_View_Helper_Abstract { public function dojoStylesheets() { $dojo = $this ->view->dojo(); $isXhtml = $this ->view->doctype()->isXhtml(); if ( $dojo ->useCdn()) { $base = $dojo ->getCdnBase() . $dojo ->getCdnVersion(); } else { $base = $dojo ->_getLocalRelativePath(); } $registeredStylesheets = $dojo ->getStylesheetModules(); foreach ( $registeredStylesheets as $stylesheet ) { $themeName = substr ( $stylesheet , strrpos ( $stylesheet , '.' ) + 1); $stylesheet = str_replace ( '.' , '/' , $stylesheet ); $stylesheets [] = $base . '/' . $stylesheet . '/' . $themeName . '.css' ; } foreach ( $dojo ->getStylesheets() as $stylesheet ) { $stylesheets [] = $stylesheet ; } if ( $dojo ->registerDojoStylesheet()) { $stylesheets [] = $base . '/dojo/resources/dojo.css' ; } if ( empty ( $stylesheets )) { return '' ; } array_reverse ( $stylesheets ); $style = '<style type="text/css">' . PHP_EOL . (( $isXhtml ) ? '<!--' : '<!--' ) . PHP_EOL; foreach ( $stylesheets as $stylesheet ) { $style .= ' @import "' . $stylesheet . '";' . PHP_EOL; } $style .= (( $isXhtml ) ? '-->' : '-->' ) . PHP_EOL . '</style>' ; return $style ; } } |
Now my {action}.ajax.phtml script is nice and happy.
1 2 3 4 5 6 7 8 | // call the regular members action page - no need to duplicate code! echo $this ->render( 'team-manager/members.phtml' ); // inlineScript contains all the formatters for the grid echo $this ->inlineScript(); // New view helper to include the data grid CSS files generated by my DataGrid view helper echo $this ->dojoStylesheets(); |