Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm glad Ding is helping you. I contributed on this project and also needed to integrate with a Zend Framework application. I used Zend's application resources and plugin system to achieve this.</p> <p>An application resource (you can reuse among projects)</p> <pre><code>&lt;?php class Application_Resource_Ding extends Zend_Application_Resource_ResourceAbstract { protected $_options = array( 'factory' =&gt; array( 'bdef' =&gt; array( 'xml' =&gt; array( 'filename' =&gt; array('beans.xml') ), ), ), 'cache' =&gt; array( 'proxy' =&gt; array('impl' =&gt; 'dummy'), 'bdef' =&gt; array('impl' =&gt; 'dummy'), 'beans' =&gt; array('impl' =&gt; 'dummy') ) ); public function init() { // set default config dir before mergin options (cant be set statically) $this-&gt;_options['factory']['bdef']['xml']['directories'] = array(APPLICATION_PATH .'/configs'); $options = $this-&gt;getOptions(); // parse factory properties (if set) if (isset($options['factory']['properties'])) { $options['factory']['properties'] = parse_ini_file( $options['factory']['properties'] ); } // change log4php_properties for log4php.properties (if exists) if (isset($options['log4php_properties'])) { $options['log4php.properties'] = $options['log4php_properties']; unset($options['log4php_properties']); } $properties = array( 'ding' =&gt; $options ); return Ding\Container\Impl\ContainerImpl::getInstance($properties); } } </code></pre> <p>An action helper to use inside the controllers:</p> <pre><code>&lt;?php class Application_Action_Helper_Ding extends Zend_Controller_Action_Helper_Abstract { protected $ding = null; public function init() { // just once... if (null !== $this-&gt;ding) { return; } // get ding bootstrapped resource $bootstrap = $this-&gt;getActionController()-&gt;getInvokeArg('bootstrap'); $ding = $bootstrap-&gt;getResource('ding'); if (!$ding) { throw new Zend_Controller_Action_Exception( 'Ding resource not bootstrapped' ); } $this-&gt;ding = $ding; } public function getBean($bean) { return $this-&gt;ding-&gt;getBean($bean); } public function direct($bean) { return $this-&gt;getBean($bean); } } </code></pre> <p>In your <code>application.ini</code> you should add something like this (plus any extra configuration you need)</p> <pre><code>resources.frontController.actionHelperPaths.Application_Action_Helper = "Application/Action/Helper" resources.ding.factory.properties = APPLICATION_PATH "/configs/ding.properties" resources.ding.log4php_properties = APPLICATION_PATH "/configs/log4php.properties" </code></pre> <p>And then in your controllers, to request a bean:</p> <pre><code>$service = $this-&gt;_helper-&gt;ding('someService'); </code></pre> <p>Hope this helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload