<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Börngen-Schmidt IT Consulting &#187; Doctrine</title>
	<atom:link href="http://www.boerngen-schmidt.de/tag/doctrine/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.boerngen-schmidt.de</link>
	<description>Die Summe der Kleinigkeiten ergibt das Ganze.</description>
	<lastBuildDate>Mon, 07 Nov 2011 20:00:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Doctrine und Agavi</title>
		<link>http://www.boerngen-schmidt.de/2009/04/howto-configure-doctrine-and-agavi/</link>
		<comments>http://www.boerngen-schmidt.de/2009/04/howto-configure-doctrine-and-agavi/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 22:06:59 +0000</pubDate>
		<dc:creator>Benjamin</dc:creator>
				<category><![CDATA[Allgemeines]]></category>
		<category><![CDATA[Agavi]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[HowTo]]></category>

		<guid isPermaLink="false">http://www.boerngen-schmidt.de/?p=141</guid>
		<description><![CDATA[Bei Agavi hat man die Qual der Wahl wie man eine Datenbankverbindung herstellt. Zum einen sind dort Propel und Doctrine als Verfechter der ORMs, zum anderen aber auch die klassischen Methode ala PDO.

Heute möchte ich gerne ein paar Worte dazu verlieren wie man Doctrine zusammen mit Agavi einrichtet und zum laufen bekommt.


Keine verwandten Artikel gefunden.]]></description>
			<content:encoded><![CDATA[<h2>Doctrine Librarys</h2>
<p>Als erstes sollte man sich die Librarys von Doctrine besorgen. Ich selber speichere alle externen librarys im Verzeichnis <strong>%project_dir%/libs</strong> ab.</p>
<p>svn co <a href="http://svn.doctrine-project.org/tags/1.1.0/lib/">http://svn.doctrine-project.org/tags/1.1.0/lib/</a> libs/doctrine</p>
<p>nun haben wir schon einmal die Librarys im Verzeichnis %project_dir%/lib/doctrine.</p>
<p><strong>Konfiguration in Agavi</strong></p>
<p>Damit Agavi nun diese auch läd müssen sie zur autoload.xml hinzugefügt werden.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- Doctrine --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;autoload</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Doctrine&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>/path/to/project/libs/doctrine/Doctrine.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/autoload<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Zum anderen sollte in settings.xml <em>use_database</em> auf true gesetzt werden, damit Agavi überhaupt zu Datenbanken verbindet. Als nächstes ist nun die database.xml an der Reihe. Die hier angegebene Konfiguration sollte immer an die eingenen Wünsche angepasst werden!</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:configurations</span> <span style="color: #000066;">xmlns:ae</span>=<span style="color: #ff0000;">&quot;http://agavi.org/agavi/config/global/envelope/1.0&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://agavi.org/agavi/config/parts/databases/1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;databases</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;doctrine&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;database</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;doctrine&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;AgaviDoctrineDatabase&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dsn&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>mysql://<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;username<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>:<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;password<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>@<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;host<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;databasename<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/ae:parameter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;attributes&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;AUTOLOAD_TABLE_CLASSES&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ae:parameter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;VALIDATE&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>LENGTHS<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ae:parameter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;AUTO_ACCESSOR_OVERRIDE&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ae:parameter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ae:parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ae:parameter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;manager_attributes&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;model_loading&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>conservative<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ae:parameter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ae:parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ae:parameter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ae:parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;load_models&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>%core.lib_dir%/doctrine<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ae:parameter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ae:parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/database<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/databases<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ae:configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ae:configurations<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>Entwicklungsumgebung</h2>
<p>Hier habe ich mir angewöhnt die Sachen für die DB Entwicklung unter dev/db ab zuspeichern. Hier sollten folgende Verzeichnisse erstellt werden.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> dev<span style="color: #000000; font-weight: bold;">/</span>db<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>data,data<span style="color: #000000; font-weight: bold;">/</span>fixtures,data<span style="color: #000000; font-weight: bold;">/</span>sql,migrations,models,schema<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Zudem erzeugen wir in dev/db noch die Datei doctrine.php, welches wir zur Konfiguration der Doctrine CLI verweden werden. Auch hier gilt, bitte anpassen!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Backup argv, otherwise stripped by agavi</span>
<span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argv'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'../../libs/agavi/agavi.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'../../app/config.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Agavi<span style="color: #339933;">::</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'development.benjamin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">spl_autoload_register</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Doctrine'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'autoload'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Let Agavi create the connection</span>
<span style="color: #000088;">$con</span> <span style="color: #339933;">=</span> AgaviContext<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'console'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDatabaseConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'data_fixtures_path'</span>  <span style="color: #339933;">=&gt;</span> AgaviConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'doctrine.fixture_dir'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dir</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/data/fixtures'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'models_path'</span> <span style="color: #339933;">=&gt;</span> AgaviConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core.lib_dir'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/doctrine'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'migrations_path'</span> <span style="color: #339933;">=&gt;</span>  AgaviConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'doctrine.migration_dir'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dir</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/migrations'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'sql_path'</span> <span style="color: #339933;">=&gt;</span> AgaviConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'doctrine.migration_dir'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dir</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/data/sql'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'yaml_schema_path'</span> <span style="color: #339933;">=&gt;</span>  AgaviConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'doctrine.schema_dir'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dir</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/schema/schema.yml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'generate_models_options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'suffix'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'.class.php'</span>
	<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Configure Doctrine Cli</span>
<span style="color: #000088;">$cli</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Doctrine_Cli<span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cli</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Kommen wir nun zur letzten kleine Hürde. Wir brauchen noch eine entsprechende Datei die uns die doctrine.php von oben aufruft. Diese platziere ich immer in dev/ und sie sieht so aus.</p>
<pre lang="bash" file="doctrine">
#!/usr/bin/env php
<?PHP
chdir(dirname(__FILE__).'/db');
include('doctrine.php');
?>
</pre>
<p>Noch ein abschließendes chmod +x doctrine und man kann los legen.</p>


<p>Keine verwandten Artikel gefunden.</p>]]></content:encoded>
			<wfw:commentRss>http://www.boerngen-schmidt.de/2009/04/howto-configure-doctrine-and-agavi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

