<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Zendcasts Forum / Bootstrapping Doctrine in Zend 1.8 or 1.9]]></title>
		<link>http://www.zendcasts.com/forum/viewtopic.php?id=26</link>
		<description><![CDATA[The most recent posts in Bootstrapping Doctrine in Zend 1.8 or 1.9.]]></description>
		<lastBuildDate>Wed, 30 Dec 2009 17:07:55 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Re: Bootstrapping Doctrine in Zend 1.8 or 1.9]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=535#p535</link>
			<description><![CDATA[<p>Hi Jon,</p><p>your article was indeed very helpful. Doctrine works like a charm now.</p><p>I made some improvements/changes to your sourcecode however... maybe you find them useful. </p><p>Method in the Bootstrap class:<br />[code=php]<br />protected function _initDoctrine()<br />&#160; &#160; {<br />&#160; &#160; &#160; &#160;// get options from application.ini rather than defining all paths in the bootstrap class again<br />&#160; &#160; &#160; &#160; $options = $this-&gt;getOptions();<br />&#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; if ( !isset( $options[&#039;doctrine&#039;][&#039;connection_string&#039;] ) ) {<br />&#160; &#160; &#160; &#160; &#160; &#160; // doctrine not needed at all...<br />&#160; &#160; &#160; &#160; &#160; &#160; return ;<br />&#160; &#160; &#160; &#160; }<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; require_once &#039;Doctrine/Doctrine.php&#039;;</p><p>&#160; &#160; &#160; &#160; spl_autoload_register(array(&#039;Doctrine&#039;, &#039;autoload&#039;));<br />&#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; $manager = Doctrine_Manager::getInstance();<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; $connection = $manager-&gt;connection( $options[&#039;doctrine&#039;][&#039;connection_string&#039;] );<br />&#160; &#160; &#160; &#160; $connection-&gt;setCharset(&#039;UTF8&#039;);<br />&#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; $manager-&gt;setAttribute( Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE );<br />&#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; // if models_path is not set, assume it&#039;s in application/models<br />&#160; &#160; &#160; &#160; $modelPath = isset( $options[&#039;doctrine&#039;][&#039;models_path&#039;]&#160; ) ? $options[&#039;doctrine&#039;][&#039;models_path&#039;] : APPLICATION_PATH.DIRECTORY_SEPARATOR.&#039;models&#039;;<br />&#160; &#160; &#160; &#160; Doctrine::loadModels( $modelPath );<br />&#160; &#160; }<br />[/code]</p><p>... and my doctrine_cli.php:<br />[code=php]<br />error_reporting(E_ALL);</p><p>// Define path to application directory<br />defined(&#039;APPLICATION_PATH&#039;)<br />&#160; &#160; || define(&#039;APPLICATION_PATH&#039;, dirname(realpath(dirname(__FILE__))).DIRECTORY_SEPARATOR.&#039;application&#039;);</p><p>define(&#039;DOCTRINE_PATH&#039;, APPLICATION_PATH.DIRECTORY_SEPARATOR.&#039;doctrine&#039;);</p><p>// Define application environment<br />defined(&#039;APPLICATION_ENV&#039;)<br />&#160; &#160; || define(&#039;APPLICATION_ENV&#039;, (getenv(&#039;APPLICATION_ENV&#039;) ? getenv(&#039;APPLICATION_ENV&#039;) : &#039;development&#039;));</p><p>//Ensure library/ is on include_path<br />set_include_path(implode(PATH_SEPARATOR, array(<br />&#160; &#160; realpath(APPLICATION_PATH . &#039;/../library&#039;),<br />&#160; &#160; get_include_path(),<br />)));</p><p>/** Zend_Application */<br />require_once &#039;Zend/Application.php&#039;;&#160; </p><p>// Create application, bootstrap, and run<br />$application = new Zend_Application(<br />&#160; &#160; APPLICATION_ENV, <br />&#160; &#160; APPLICATION_PATH . &#039;/configs/application.ini&#039;<br />);</p><p>$application-&gt;getBootstrap()-&gt;bootstrap(&quot;doctrine&quot;);</p><p>// Configure Doctrine Cli<br />// Normally these are arguments to the cli tasks but if they are set here the arguments will be auto-filled<br />$options = $application-&gt;getOptions();<br />$config = array(<br />&#160; &#160; &#160; &#160; &#160; &#160; &#039;models_path&#039;&#160; &#160; &#160; &#160; &#160;=&gt; isset( $options[&#039;doctrine&#039;][&#039;models_path&#039;] ) ? $options[&#039;doctrine&#039;][&#039;models_path&#039;] : APPLICATION_PATH.DIRECTORY_SEPARATOR.&#039;models&#039;,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#039;data_fixtures_path&#039;&#160; =&gt; isset( $options[&#039;doctrine&#039;][&#039;data_fixtures_path&#039;] ) ? $options[&#039;doctrine&#039;][&#039;data_fixtures_path&#039;] : DOCTRINE_PATH.DIRECTORY_SEPARATOR.&#039;data&#039;.DIRECTORY_SEPARATOR.&#039;fixtures&#039;,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#039;sql_path&#039;&#160; &#160; &#160; &#160; &#160; &#160; =&gt; isset( $options[&#039;doctrine&#039;][&#039;sql_path&#039;] ) ? $options[&#039;doctrine&#039;][&#039;sql_path&#039;] : DOCTRINE_PATH.DIRECTORY_SEPARATOR.&#039;data&#039;.DIRECTORY_SEPARATOR.&#039;sql&#039;,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#039;migrations_path&#039;&#160; &#160; &#160;=&gt; isset( $options[&#039;doctrine&#039;][&#039;migrations_path&#039;] ) ? $options[&#039;doctrine&#039;][&#039;migrations_path&#039;] : DOCTRINE_PATH.DIRECTORY_SEPARATOR.&#039;migrations&#039;,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#039;yaml_schema_path&#039;&#160; &#160; =&gt; isset( $options[&#039;doctrine&#039;][&#039;yaml_schema_path&#039;] ) ? $options[&#039;doctrine&#039;][&#039;yaml_schema_path&#039;] : DOCTRINE_PATH.DIRECTORY_SEPARATOR.&#039;schema&#039;<br />);</p><p>$cli = new Doctrine_Cli( $config );<br />$cli-&gt;run( $_SERVER[&#039;argv&#039;] );<br />[/code]</p><p>Pros:<br />- doctrine settings only need to be defined in application.ini<br />- only &quot;connection_string&quot; setting is mandatory</p><p>Note: I&#039;m only getting started with my first Zend/Doctrine project so this might not be the &quot;expert solution&quot;.</p>]]></description>
			<author><![CDATA[dummy@example.com (chmuul)]]></author>
			<pubDate>Wed, 30 Dec 2009 17:07:55 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=535#p535</guid>
		</item>
		<item>
			<title><![CDATA[Bootstrapping Doctrine in Zend 1.8 or 1.9]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=68#p68</link>
			<description><![CDATA[<p>I&#039;ve been using Doctrine a lot as an alternative to Zend_Db with great success. here&#039;s my bootstrap method (sits in the Bootstrap.php file) in case anyone is interested:</p><br /><p>[code=php]<br />&#160; &#160; protected function _initDoctrine()<br />&#160; &#160; {<br />&#160; &#160; &#160; &#160; $this-&gt;bootstrap(&quot;autoload&quot;);</p><p>&#160; &#160; &#160; &#160; $dbConfig = $this-&gt;options[&#039;db&#039;];<br />&#160; &#160; &#160; &#160; defined(&#039;CONFIG_PATH&#039;) &#160; &#160; &#160; &#160; &#160; &#160; || define(&#039;CONFIG_PATH&#039;, APPLICATION_PATH . &#039;/configs&#039;);&#160; &#160; <br />&#160; &#160; &#160; &#160; defined(&#039;DATA_FIXTURES_PATH&#039;) &#160; &#160; || define(&#039;DATA_FIXTURES_PATH&#039;, &#160; &#160; CONFIG_PATH . &#039;/data/fixtures&#039;);<br />&#160; &#160; &#160; &#160; defined(&#039;SQL_PATH&#039;) &#160; &#160; &#160; &#160; &#160; &#160; || define(&#039;SQL_PATH&#039;, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; CONFIG_PATH . &#039;/data/sql&#039;);<br />&#160; &#160; &#160; &#160; defined(&#039;MIGRATIONS_PATH&#039;) &#160; &#160; &#160; &#160; || define(&#039;MIGRATIONS_PATH&#039;, &#160; &#160; &#160; &#160; CONFIG_PATH . &#039;/migrations&#039;);<br />&#160; &#160; &#160; &#160; defined(&#039;YAML_SCHEMA_PATH&#039;) &#160; &#160; || define(&#039;YAML_SCHEMA_PATH&#039;, &#160; &#160; &#160; &#160; CONFIG_PATH . &#039;/schema.yml&#039;);<br />&#160; &#160; &#160; &#160; defined(&#039;MODELS_PATH&#039;) &#160; &#160; &#160; &#160; &#160; &#160; || define(&#039;MODELS_PATH&#039;, &#160; &#160; &#160; &#160; &#160; &#160; APPLICATION_PATH . &#039;/models&#039;);<br />&#160; &#160; &#160; &#160; defined(&#039;DB_PATH&#039;) &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; || define(&#039;DB_PATH&#039; , &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#039;mysql://&#039; . $dbConfig[&#039;username&#039;]. &#039;:&#039; . $dbConfig[&#039;password&#039;]. &#039;@&#039; . $dbConfig[&#039;host&#039;]. &#039;/&#039; . $dbConfig[&#039;name&#039;]);</p><p>&#160; &#160; &#160; &#160; require_once &#039;Doctrine.php&#039;;<br />&#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; spl_autoload_register(array(&#039;Doctrine&#039;, &#039;autoload&#039;));</p><p>&#160; &#160; &#160; &#160; $connection = Doctrine_Manager::connection(DB_PATH);<br />&#160; &#160; &#160; &#160; $connection-&gt;setCharset(&#039;UTF8&#039;);<br />&#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; Doctrine_Manager::getInstance()-&gt;setAttribute(&#039;model_loading&#039;, &#039;conservative&#039;);<br />&#160; &#160; &#160; &#160; Doctrine::loadModels(MODELS_PATH);<br />&#160; &#160; }<br />[/code]</p><p>this code assumes that the database configurin is sitting in your application.ini file. Also, Doctrine is sitting in /library/Doctrine. Thanks to <a href="http://www.pimpmycode.fr/">Maxime Bouroumeau</a>, I&#039;ve also got a modified version of the Doctrine.php command line script:</p><p>[code=php]<br />&lt;?php<br />error_reporting(E_ALL);</p><p>define(&#039;ROOT_PATH&#039;, dirname(dirname(dirname(__FILE__))));<br />define(&#039;APPLICATION_PATH&#039;, realpath(dirname(__FILE__) . &#039;/..&#039;));<br />define(&#039;APPLICATION_ENV&#039;, &#039;development&#039;);<br />define(&#039;TMP_PATH&#039;, realpath(dirname(__FILE__) . &#039;/../tmp/&#039;));</p><br /><p>//Ensure library/ is on include_path<br />set_include_path(implode(PATH_SEPARATOR, array(<br />&#160; &#160; realpath(APPLICATION_PATH . &#039;/../library&#039;),<br />&#160; &#160; get_include_path(),<br />)));</p><p>/** Zend_Application */<br />require_once &#039;Zend/Application.php&#039;;&#160; </p><p>// Create application, bootstrap, and run<br />$application = new Zend_Application(<br />&#160; &#160; APPLICATION_ENV, <br />&#160; &#160; APPLICATION_PATH . &#039;/configs/application.ini&#039;<br />);</p><p>$application-&gt;getBootstrap()-&gt;bootstrap(&quot;doctrine&quot;);</p><p>// Configure Doctrine Cli<br />// Normally these are arguments to the cli tasks but if they are set here the arguments will be auto-filled<br />$config = array(&#039;data_fixtures_path&#039;&#160; =&gt;&#160; DATA_FIXTURES_PATH,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#039;models_path&#039;&#160; &#160; &#160; &#160; &#160;=&gt;&#160; MODELS_PATH,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#039;migrations_path&#039;&#160; &#160; &#160;=&gt;&#160; MIGRATIONS_PATH,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#039;sql_path&#039;&#160; &#160; &#160; &#160; &#160; &#160; =&gt;&#160; SQL_PATH,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#039;yaml_schema_path&#039;&#160; &#160; =&gt;&#160; YAML_SCHEMA_PATH);</p><br /><p>$cli = new Doctrine_Cli($config);<br />$cli-&gt;run($_SERVER[&#039;argv&#039;]);<br />[/code]</p><p>Hope this helps other integrators!</p>]]></description>
			<author><![CDATA[dummy@example.com (Jon Lebensold)]]></author>
			<pubDate>Sat, 15 Aug 2009 06:06:35 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=68#p68</guid>
		</item>
	</channel>
</rss>

