SpiffyJr's Blogaroo

Happenings of the man known as SpiffyJr

  • Home
  • About
    • Inspiration
    • Resume
  • Projects
    • Blitzaroo
    • phpRaider
    • Zend Calendar
  • Docs
    • Blitzaroo API
    • SpiffyCalendar Docs
    • SpiffyDb Docs
  • Downloads
  • Technologies
    • Doctrine ORM
    • Dojo
    • PHP
    • Zend Framework
  • Other
    • License
Twitter RSS
Tag Archives: Zend Framework

Rendering Dojo Stylesheets with a view helper

Posted on October 26, 2010 by SpiffyJr
2 comments

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).

$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!

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.

// 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();
GD Star Rating
loading...
Categories: Blitzaroo, Dojo, PHP, View Helpers, Zend Framework | Tags: Ajax, api, Blitzaroo, Dojo, Dojo Toolkit, JavaScript, php, Programming, Scripts, Style Sheets, zend, Zend Framework

Zend_Dojo_View_Helper_Dialog

Posted on March 12, 2010 by SpiffyJr
3 comments

Quickie

I’m going to make this one short & sweet. I’ve created a view helper for Dialogs (and an extended Dijit view helper).

Zend_Dojo_View_Helper_Dijit_Extended (wtb: namespaces)

<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper_Dijit_Extended
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */

/**
 * Zend_Calendar
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper_Dijit_Extended
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Dojo_View_Helper_Dijit_Extended extends Zend_Dojo_View_Helper_Dijit
{
	/**
	 * Holds the base path for scripts.
	 */
	protected static $_scriptBase = null;

	/**
	 * Dojo for static methods.
	 */
	protected static $_dojo = null;

	/**
	 * View for static methods.
	 */
	protected static $_view = null;

	/**
	 * Static setting for script base.
	 * @param string $scriptBase Path to the base script directory.
	 */
	public static function setScriptBase($scriptBase)
	{
		self::$_scriptBase = $scriptBase;
	}

	/**
	 * Static getter for script base.
	 * @return string
	 */
	public static function getScriptBase()
	{
		return self::$_scriptBase;
	}

	/**
	 * Adds a stylesheet based on the dojo path (local or cdn).
	 * Method is static for situations where you need the stylesheets
	 * to render even if even the dijits haven't been called but
	 * will during execution (AJAX calls).
	 *
	 * @param string $stylesheet Path to stylesheet from base path.
	 */
	public static function addStylesheet($path)
	{
		// Set static view if necessary
		if (null === self::$_view) {
			$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
			self::$_view = $viewRenderer->view;
			self::$_dojo = self::$_view->dojo();
		}

		// Determine path to use
		if (null === self::getScriptBase()) {
			if (self::$_dojo->useLocalPath()) {
				self::setScriptBase(self::$_dojo->getLocalPath());
			} else {
				self::setScriptBase(self::$_dojo->getCdnBase() . self::$_dojo->getCdnVersion());
			}
		}

		self::$_dojo->addStylesheet(self::getScriptBase() . $path);
	}
}

Zend_Dojo_View_Helper_Dialog

Pretty simple view helper that renders a dialog using the regular (dijit.Dialog) method or the dojox (dojox.widget.Dialog) method.

Usage

// Regular dialog
<?=$this->dialog('myDialog', array('title' => 'w00t!', 'content' => 'I am a w00tastic dialog'));?>

// Enhanced dojox dialog
<?=$this->dialog('myDialog', array('title' => 'w00t!', 'content' => 'I am a w00tastic dialog'), array('useDojox' => true);?>

Code

<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper_Dialog
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */

/**
 * Zend_Calendar
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper_Dialog
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Dojo_View_Helper_Dialog extends Zend_Dojo_View_Helper_Dijit_Extended
{
	const DIALOG_DOJO = 'dijit.Dialog';
	const DIALOG_DOJOX = 'dojox.widget.Dialog';

	/**
	 * Holds the default dialog type.
	 */
	public static $_dialogType = self::DIALOG_DOJO;

	/**
	 * Sets the default dialog type to use.
	 *
	 * @param string $dojoType Type of dijit to use.
	 */
	public static function setDialogType($dojoType)
	{
		switch ($dojoType) {
			case self::DIALOG_DOJOX:
				self::$_dialogType = $dojoType;
				break;
			default:
				self::$_dialogType = self::DIALOG_DOJO;
				break;
		}
	}

	/**
	 * DataStore view helper.
	 *
	 * @param string $id JavaScript id for the dialog.
	 * @param array $attribs Attributes for the dialog.
	 * @param array $options Options for the dialog.
	 */
	public function dialog($id = '', array $attribs = array(), array $options = array())
	{
		if (!$id) {
			throw new Zend_Exception('Invalid arguments: required jsId.');
		}

		// Determine dialog type
		$dialogType = self::$_dialogType;
		if (array_key_exists('useDojox', $options)) {
			$dialogType = self::DIALOG_DOJOX;
		}

		// Require module
		$this->dojo->requireModule($dialogType);

		// Add styles
		if ($dialogType == self::DIALOG_DOJOX) {
			self::addStylesheet('/dojox/widget/Dialog/Dialog.css');
		}

		// Programmatic
		if ($this->_useProgrammatic()) {
			if (!$this->_useProgrammaticNoScript()) {
				$this->dojo->addJavascript('var ' . $id . ";\n");
				$js = $id . ' = ' . 'new ' . $dialogType . '(' . Zend_Json::encode($attribs) . ");";
				$this->dojo->_addZendLoad("function(){{$js}}");
			}
			return '';
		}

		// Set extra attribs for declarative
		if (!array_key_exists('id', $attribs)) {
			$attribs['id'] = $id;
		}

		if (!array_key_exists('jsId', $attribs)) {
			$attribs['jsId'] = $id;
		}

		if (!array_key_exists('dojoType', $attribs)) {
			$attribs['dojoType'] = $dialogType;
		}

		if (array_key_exists('content', $attribs)) {
			$content = $attribs['content'];
			unset($attribs['content']);
		}

		return '<div' . $this->_htmlAttribs($attribs) . '>' . $content . "</div>\n";
	}
}

Hope it makes life a little easier. Enjoy!

Reblog this post [with Zemanta]
GD Star Rating
loading...
Categories: Random | Tags: Ajax, BSD licenses, JavaScript, Languages, php, Programming, Source code, Zend Framework

dataStore and dataGrid view helpers.

Posted on March 10, 2010 by SpiffyJr
23 comments

Introduction

Grid’s are used everywhere and one thing the Zend Framework really lacks is a useful view helper to quickly generate grids and their stores. I saw that  Matthew Weier O’Phinney had a proposal for a dojox.grid.DataGrid view helper but no work had been done on it. I send him a tweet and learned that he had intended to finish it but is currently too busy to work on it so I wrote a few view helpers to follow his proposal. The dataStore view helper is fairly simplistic but the dataGrid view helper has quite a bit to it. I plan on refactoring the dataGrid view helper to add support for enhancedGrid and treeGrid but I wanted to share what I had done already. Both view helpers follow the use-cases as presented by Matthew in his dojox.grid.DataGrid view helper proposal.

The dataStore() helper

The dataStore() helper provides support for generating programmatic/declarative data stores and requires an id as well as a dojoType.

Usage

<?=$this->dataStore('store', 'dojox.data.QueryReadStore', array('url' => '/path/to/json'));?>

Code

<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper_DataStore
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */

/**
 * Zend_Calendar
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper_DataStore
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Dojo_View_Helper_DataStore extends Zend_Dojo_View_Helper_Dijit
{
	/**
	 * DataStore view helper.
	 *
	 * @param string $id JavaScript id for the data store.
	 * @param string $dojoType DojoType of the data store (e.g., dojox.data.QueryReadStore)
	 * @param array $attribs Attributes for the data store.
	 */
	public function dataStore($id = '', $dojoType = '', array $attribs = array())
	{
		if (!$id || !$dojoType) {
			throw new Zend_Exception('Invalid arguments: required jsId and dojoType.');
		}

		$this->dojo->requireModule($dojoType);

		// Programmatic
		if ($this->_useProgrammatic()) {
			if (!$this->_useProgrammaticNoScript()) {
				$this->dojo->addJavascript('var ' . $id . ";\n");
				$js = $id . ' = ' . 'new ' . $dojoType . '(' . Zend_Json::encode($attribs) . ");";
				$this->dojo->_addZendLoad("function(){{$js}}");
			}
			return '';
		}

		// Set extra attribs for declarative
		if (!array_key_exists('id', $attribs)) {
			$attribs['id'] = $id;
		}

		if (!array_key_exists('jsId', $attribs)) {
			$attribs['jsId'] = $id;
		}

		if (!array_key_exists('dojoType', $attribs)) {
			$attribs['dojoType'] = $dojoType;
		}

		return '<div' . $this->_htmlAttribs($attribs) . "></div>\n";
	}
}

The dataGrid() helper

The dataGrid helper provides support for generating programmatic/declarative dataGrids. Currently, the only supported grid is dojox.grid.DataGrid but I’ll be adding EnhancedGrid and TreeGrid in the future.

Usage

<?php
echo $this->dataStore('store', 'dojox.data.QueryReadStore', array('url' => '/admin/articles/grid.json'));
$grid = $this->dataGrid('myGrid',
	array(
		'selectionMode' => 'none',
		'style' => 'height: 350px; width: 100%;',
		'store' => 'store',
		'fields' => array(
			array('field' => 'title', 'label' => 'Title', 'options' => array('formatter' => 'titleFormatter', 'width' => '60%')),
			array('field' => 'published', 'label' => 'Published', 'options' => array('formatter' => 'primaryFormatter', 'width' => '10%')),
			array('field' => 'updated_at', 'label' => 'Updated', 'options' => array('width' => '15%')),
			array('field' => 'created_at', 'label' => 'Created', 'options' => array('width' => '15%')))));
?>
<?php $grid->scriptCaptureStart('dojo/method', 'onMouseOver', array('args' => 'row'));?>
var g = dojo.byId("grid-menu-item-"+row.rowIndex);
if (g) { dojo.toggleClass(g, "hide-text"); }
<?php $grid->scriptCaptureEnd();?>
<?php $grid->scriptCaptureStart('dojo/method', 'onMouseOut', array('args' => 'row'));?>
var g = dojo.byId("grid-menu-item-"+row.rowIndex);
if (g) { dojo.toggleClass(g, "hide-text"); }
<?php $grid->scriptCaptureEnd();?>
<?php echo $grid;?>

Code

<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper_DataGrid
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */

/**
 * Zend_Calendar
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper_DataGrid
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Dojo_View_Helper_DataGrid extends Zend_Dojo_View_Helper_Dijit
{
	/**
	 * Ensures only one script capture is active at a time.
	 * @var bool
	 */
	protected $_captureLock = false;

	/**
	 * Holds the attributes for the grid.
	 * @var array
	 */
	protected $_attribs = array();

	/**
	 * Holds the field data.
	 * @var array
	 */
	protected $_fields = array();

	/**
	 * Holds the data for the current script capture.
	 */
	protected $_currentScript = array();

	/**
	 * Holds the data for script captures.
	 * @var array
	 */
	protected $_scriptCapture = array();

	/**
	 * Holds the tab character.
	 * @var string
	 */
	protected $_tab = '    ';

	/**
	 * Holds the current theme.
	 */
	protected static $_theme = 'tundra';

	/**
	 * Holds the base path for scripts.
	 */
	protected static $_scriptBase = null;

	/**
	 * __toString();
	 */
	public function __toString()
	{
		return $this->render();
	}

	/**
	 * DataGrid view helper.
	 *
	 * @param string $id JavaScript id for the data store.
	 * @param array $attribs Attributes for the data store.
	 */
	public function dataGrid($id = '', array $attribs = array())
	{
		if (!$id) {
			throw new Zend_Exception('Invalid arguments: required jsId.');
		}

		if (!array_key_exists('id', $attribs)) {
			$attribs['id'] = $id;
		}

		if (array_key_exists('fields', $attribs)) {
			foreach ($attribs['fields'] as $f) {
				$this->addField($f['field'], $f['label'], isset($f['options']) ? $f['options'] : array());
			}
			unset($attribs['fields']);
		}

		$this->_attribs = $attribs;

		return $this;
	}

	/**
	 * Static setter for theme.
	 * @param string $theme Name of the current them.
	 */
	public static function setTheme($theme)
	{
		self::$_theme = $theme;
	}

	/**
	 * Static getter for theme.
	 * @return string
	 */
	public static function getTheme()
	{
		return self::$_theme;
	}

	/**
	 * Static setting for script base.
	 * @param string $scriptBase Path to the base script directory.
	 */
	public static function setScriptBase($scriptBase)
	{
		self::$_scriptBase = $scriptBase;
	}

	/**
	 * Static getter for script base.
	 * @return string
	 */
	public static function getScriptBase()
	{
		return self::$_scriptBase;
	}

	/**
	 * Adds field data.
	 * @param string $field Field name.
	 * @param string $label Label of the field.
	 * $param array $attribs Optional parameters for the field.
	 */
	public function addField($field, $label, array $attribs = array())
	{
		$this->_fields[] = array(
			'label' => $label,
			'attribs' => array_merge(array('field' => $field), $attribs));
		return $this;
	}

	/**
	 * Adds script captures.
	 * @param array $data
	 */
	public function addScriptCapture(array $script = array())
	{
		if (!array_key_exists('data', $script)) {
			throw new Zend_Exception('Script data must include keys data and attribs');
		}

		$this->_scriptCapture[] = $script;
		return $this;
	}

	/**
	 * Begins script capturing.
	 */
	public function scriptCaptureStart($type, $event, array $attribs = array())
	{
		if ($this->_captureLock) {
			throw new Zend_Exception('Cannot nest captures.');
		}

		$this->_currentScript = array('type' => $type, 'event' => $event, 'attribs' => $attribs);

		$this->_captureLock = true;
		ob_start();
		return;
	}

	/**
	 * Ends script capturing.
	 */
	public function scriptCaptureEnd()
	{
		$data = ob_get_clean();
		$this->_captureLock = false;

		$this->_currentScript['data'] = $data;

		$this->addScriptCapture($this->_currentScript);
		$this->_currentScript = array();

		return true;
	}

	/**
	 * Renders the grid based on programmatic setting.
	 */
	public function render()
	{
		$this->dojo->requireModule('dojox.grid.DataGrid');

		// Setup the stylesheet base path
		if (null === self::getScriptBase()) {
			if ($this->dojo->useLocalPath()) {
				self::setScriptBase($this->dojo->getLocalPath());
			} else {
				self::setScriptBase($this->dojo->getCdnBase() . $this->dojo->getCdnVersion());
			}
		}

		$this->dojo->addStylesheet(self::getScriptBase() . '/dojox/grid/resources/Grid.css');
		$this->dojo->addStylesheet(
			self::getScriptBase() . '/dojox/grid/resources/' . self::getTheme() . 'Grid.css');

		// Programmatic
		if ($this->_useProgrammatic()) {
			if (!$this->_useProgrammaticNoScript()) {
				$this->_renderJavascript();
			}
			return '<div id="' . $this->_attribs['id'] . '"></div>';
		}

		return $this->_renderDeclarative();
	}

	/**
	 * Renders a table for declarative grids.
	 */
	protected function _renderDeclarative()
	{
		if (!array_key_exists('jsId', $this->_attribs)) {
			$this->_attribs['jsId'] = $this->_attribs['id'];
		}

		$table = '<table dojoType="dojox.grid.DataGrid"' . $this->_htmlAttribs($this->_attribs) . ">\n";

		foreach ($this->_scriptCapture as $s) {
			$attribs = array_merge($s['attribs'], array('event' => $s['event'], 'type' => $s['type']));
			$table .= "\t<script" . $this->_htmlAttribs($attribs) . ">\n";
			$table .= "\t\t" . $s['data'];
			$table .= "\t</script>\n";
		}

		$table .= "\t<thead>\n";
		$table .= "\t\t<tr>\n";

		foreach ($this->_fields as $f) {
			$table .= "\t\t\t<th" . $this->_htmlAttribs($f['attribs']) . '>' . $f['label'] . "</th>\n";
		}

		$table .= "\t\t</tr>\n";
		$table .= "\t</thead>\n";
		$table .= "</table>\n";

		return $table;
	}

	/**
	 * Renders javascript for programmatic declaration.
	 */
	protected function _renderJavascript()
	{
		$tab = $this->_tab;

		// Grid names
		$gridName = $this->_attribs['id'] . 'Grid';
		$layoutName = $this->_attribs['id'] . 'Layout';

		$this->dojo->addJavascript('var ' . $gridName . ";\n");

		// Setup layout
		$js = $tab . 'var ' . $layoutName . " = [\n";
		foreach ($this->_fields as $f) {
			$f['attribs']['name'] = $f['label'];

			$f['attribs'] = $this->_jsonExpr($f['attribs']);
			$js .= "{$tab}{$tab}{$tab}" . Zend_Json::encode($f['attribs'], false,
				array('enableJsonExprFinder' => true)) . ",\n";
		}

		$js = substr($js, 0, -2);
		$js .= "];\n\n";

		// Use expressions for structure, store, formatter, and get
		$this->_attribs = $this->_jsonExpr($this->_attribs);
		$this->_attribs['structure'] = new Zend_Json_Expr($layoutName);

		// Generate grid
		$js .= $tab . $tab . $gridName . ' = ' . 'new dojox.grid.DataGrid(' . Zend_Json::encode(
			$this->_attribs, false, array('enableJsonExprFinder' => true)) . "), document.createElement('div');\n";

		$js .= $tab . $tab . 'dojo.byId("' . $this->_attribs['id'] . '").appendChild(' . $gridName . '.domNode);' .
			 "\n";
		$js .= $tab . $tab . $gridName . ".startup();\n";

		// Generate connects for script captures
		foreach ($this->_scriptCapture as $s) {
			$s['data'] = trim($s['data'], "\r\n");
			$args = isset($s['attribs']['args']) ? $s['attribs']['args'] : '';

			$js .= "{$tab}{$tab}dojo.connect({$gridName}, \"{$s['event']}\", function({$args}){{$s['data']}});\n";
		}

		$this->dojo->_addZendLoad("function(){\n{$tab}{$js}\n{$tab}}");
	}

	/**
	 * Parses an array looking for keys that should be Zend_Json_Expr()'s and coverts them.
	 */
	protected function _jsonExpr(array $data)
	{
		$jsonExprAttr = array('formatter', 'get', 'query', 'store');

		foreach ($jsonExprAttr as $exp) {
			if (array_key_exists($exp, $data)) {
				$data[$exp] = new Zend_Json_Expr($data[$exp]);
			}
		}

		return $data;
	}
}

Final Thoughts

These view helpers are by no means complete but I will say that I’m currently using them in a production environment with no issues. I tested both declarative/programmatic usage and both functioned as expected. I also wanted to note that I’m by no means intending to step on Matthew’s toes but I know how busy he is with Zend Framework 2.0 (among other things). If anyone has any thoughts or use for this please comment below and, who knows, maybe I’ll make a proposal for it (or take over Matthew’s).

Reblog this post [with Zemanta]
GD Star Rating
loading...
Categories: Projects, Technologies, View Helpers, Zend Framework | Tags: BSD licenses, JavaScript, Languages, php, Programming, Scripts, Source code, Zend Framework
Page 1 of 212
  • Recent Posts

    • Keep your Git fork clean
    • Get started with Zend Framework 2 modules!
    • More Doctrine 2 and Zend Framework integration goodies!
    • Super sexy URLs with ZF and the joy of controller plugins!
    • Formatting your API to work with dojox.data.JsonRestStore (#dojo)
  • Categories

    • Other
      • Random
    • Projects
      • Blitzaroo
      • phpRaider
      • SpiffyDb
      • View Helpers
      • Zend Calendar
    • SpiffyJr
    • Technologies
      • Dojo
      • PHP
      • Zend Framework
  • Tag Cloud

      Ajax Algorithm api Blitzaroo Blog BSD licenses calendar Cascading Style Sheets CSS database Data Formats Dojo Dojo Toolkit event Framework game Google HTML HTML element JavaScript JQuery json Languages mapper Marketing mmorpg model php Programming Projects Scripts Source code Style sheet Style Sheets Twitter Website zend Zend Framework
  • Archives

    • December 2011
    • November 2011
    • July 2011
    • April 2011
    • March 2011
    • December 2010
    • November 2010
    • October 2010
    • March 2010
    • February 2010
    • November 2009
    • October 2009
    • September 2009
© SpiffyJr's Blogaroo. Proudly Powered by WordPress | Nest Theme by YChong