<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Strzałek's devblog</title>
	
	<link>http://strzalek.net/blog</link>
	<description>Just another devblog</description>
	<pubDate>Thu, 05 Jun 2008 15:40:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/strzalek-devblog" type="application/rss+xml" /><item>
		<title>Agavi - Wprowadzenie</title>
		<link>http://feeds.feedburner.com/~r/strzalek-devblog/~3/291868290/agavi-wprowadzenie</link>
		<comments>http://strzalek.net/blog/5/agavi-wprowadzenie#comments</comments>
		<pubDate>Fri, 16 May 2008 19:48:33 +0000</pubDate>
		<dc:creator>Strzałek</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[agavi]]></category>

		<category><![CDATA[framework]]></category>

		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://strzalek.net/blog/?p=5</guid>
		<description><![CDATA[Agavi jest frameworkiem MVC napisanym w PHP5. Jest on stosunkowo słabo znany w środowisku programistów PHP. Przyczyną tego jest to iż dopiero od niedawna dostępne jest Agavi oznaczone wersją 0.11, które ma zamrożone API. Jednak przede wszystkim framework ten nadal nie posiada dokumentacji, co właściwie go dyskwalifikuje. Developerzy Agavi obiecują że dokumentacja się wreszcie pojawi, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://agavi.org/">Agavi</a> jest frameworkiem MVC napisanym w PHP5. Jest on stosunkowo słabo znany w środowisku programistów PHP. Przyczyną tego jest to iż dopiero od niedawna dostępne jest Agavi oznaczone wersją 0.11, które ma zamrożone API. Jednak przede wszystkim framework ten nadal nie posiada dokumentacji, co właściwie go dyskwalifikuje. Developerzy Agavi obiecują że dokumentacja się wreszcie pojawi, ja tymczasem postaram się częściowo załatać dziurę serią artykułów o tym świetnym frameworku.<span id="more-5"></span></p>
<h3>Model View Controller</h3>
<p>Tak jak pisałem we wstępie - Agavi jest frameworkiem którego działanie opiera się na wzorcu projektowym - <a href="http://pl.wikipedia.org/wiki/MVC">MVC - Model View Controller</a>.</p>
<p>Wg. tego wzorca aplikacja dzieli się na 3 części. Nie zagłębiając się w szczegóły odpowiednie warstwy odpowiadają za</p>
<ul>
<li><strong>Model</strong> - pozyskiwanie danych (Baza danych, Web Services etc.)</li>
<li><strong>View (Widok)</strong> - przedstawienie pozyskanych danych użytkownikowi (zwrócenie html, xml, pdf etc.)</li>
<li><strong>Controller (Kontroler)</strong> - analiza żądania użytkownika i uruchomienie odpowiedniego modelu i widoku.</li>
</ul>
<p>W Agavi znajdują się dodatkowo akcje które to są wywoływane przez kontroler. Akcja natomiast może posiadać kilka widoków.</p>
<h3>Instalacja</h3>
<p>Zacznijmy od utworzenia struktury folderów na naszym serwerze. Składać się na nią będą:</p>
<ul>
<li><strong>/agavi_application</strong>
<ul>
<li><strong>/app</strong> - nasza aplikacja</li>
<li><strong>/dev</strong> - narzędzia które będą pomoce w momencie tworzenia aplikacji</li>
<li><strong>/libs</strong> - biblioteki (agavi, doctrine, smarty etc.)</li>
<li><strong>/pub</strong> - publiczny folder</li>
</ul>
</li>
</ul>
<p>Możemy ściągnąć najnowszą wersję Agavi ze <a href="http://agavi.org/">strony frameworka</a>. W momencie pisania artykuły najnowszą wersją jest 0.11.1. Po ściągnięciu, należy rozpakować paczkę, zmienić nazwę folderu na &#8220;agavi&#8221; i przenieść go do folderu libs.</p>
<p>Następnie przygotujmy sobie generatora. Skrypt ten używa <a href="http://phing.info/">phing&#8217;a</a>, aby go zainstalować należy wykonać następujące komendy w konsoli (musisz mieć skonfigurowany <a href="http://pear.php.net/">pear</a>).</p>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_49209999312d6">
<div class="synthi_header" style="font-weight:bold;">  <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_49209999312d6').style.display='block';document.getElementById('plain_synthi_49209999312d6').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_49209999312d6">
<div class="synthi_header" style="font-weight:bold;">  <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_49209999312d6').style.display='block';document.getElementById('styled_synthi_49209999312d6').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$ pear channel-discover pear.phing.info
</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$ pear install phing/phing</div>
</li>
</ol>
</div>
</div>
<p>Skopiujmy skrypt agavi.bat-dist, który znajduje się w /libs/agavi/etc, do /dev zmieniając jego nazwę na agavi.bat. Używając naszego ulubionego edytora tekstowego zmieńmy ścieżki znajdujące się w skrypcie:</p>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_4920999931500">
<div class="synthi_header" style="font-weight:bold;">  <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4920999931500').style.display='block';document.getElementById('plain_synthi_4920999931500').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_4920999931500">
<div class="synthi_header" style="font-weight:bold;">  <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4920999931500').style.display='block';document.getElementById('styled_synthi_4920999931500').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set PHING_COMMAND=C:\Server\php\phing.bat
</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set AGAVI_INSTALLATION=C:\Server\www\agavi_application\libs\agavi\src</div>
</li>
</ol>
</div>
</div>
<p>Tak wyglądają ścieżki w moim przypadku. Pierwsza wskazuje plik skryptu phing, druga źródła agavi.</p>
<p>Mając już gotowe narzędzie możemy uruchomić konsole i wykonać skrypt agavi.bat:</p>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_49209999316e0">
<div class="synthi_header" style="font-weight:bold;">  <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_49209999316e0').style.display='block';document.getElementById('plain_synthi_49209999316e0').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_49209999316e0">
<div class="synthi_header" style="font-weight:bold;">  <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_49209999316e0').style.display='block';document.getElementById('styled_synthi_49209999316e0').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">C:\Server\www\agavi_application&gt; dev\agavi.bat project</div>
</li>
</ol>
</div>
</div>
<p>Skrypt będzie nas pytał o różne ciekawe rzeczy. My grzecznie za każdym razem wciskamy enter. Po ok 45 sek. generator powinien poinformować nas że zakończył swoją pracę sukcesem, natomiast my po uruchomieniu aplikacji - http://localhost/agavi_application/pub/ powinniśmy zobaczyć logo agavi. Oznaczać to będzie że wszystko generator stworzył za nas pierwszą aplikację opierającą się na Agavi.</p>
<h3>Budowa aplikacji</h3>
<p>Aplikacje pisane na Agavi mają budowę modularną. Każdy moduł składa się z akcji. Akcja może mieć kilka widoków, widok natomiast może używać różnych szablonów. Przykładowo: moduł News, posiada akcję Add, która posiada widoki Input (formularz dodawania newsa) oraz Success (wiadomość o dodaniu newsa). </p>
<p>Tak w dużym skrócie wyglądają moduły. Moduły dodatkowo mogą posiadać własną konfigurację, pliki validatora, lub inne biblioteki które są używane przez moduł.</p>
<p>Stwórzmy sobie przykładowy moduł Notes, który będzie modułem notek bloga. Wygenerujmy sobie ten moduł używając generatora agavi:</p>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_49209999318ce">
<div class="synthi_header" style="font-weight:bold;">  <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_49209999318ce').style.display='block';document.getElementById('plain_synthi_49209999318ce').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_49209999318ce">
<div class="synthi_header" style="font-weight:bold;">  <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_49209999318ce').style.display='block';document.getElementById('styled_synthi_49209999318ce').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$ dev\agavi.bat module</div>
</li>
</ol>
</div>
</div>
<p>Generator będzie pytał nas o:</p>
<ol>
<li>Nazwa modułu: <strong>Notes</strong></li>
<li>Akcje: <strong>Index,ShowOne,Add</strong></li>
<li>Widoki dla akcji <em>Index,ShowOne</em>: <strong>Success</strong> (obie akcje tylko po 1 widoku), dla akcji <em>Add</em>: <strong>Success,Input</strong></li>
<li>Modele: <strong>Notes</strong></li>
</ol>
<p>Generator powinien stworzyć za nas wszystkie foldery, pliki z szablonami klas, oraz puste pliki szablonów. Pozostaje nam teraz dopisać logikę aplikacji.</p>
<h3>Konfiguracja</h3>
<p>Agavi jest frameworkiem który w dużym stopniu opiera się na konfiguracji. Konfiguracja znajduje się w plikach XML, składa się na nią 13 podstawowych plików oraz dodatkowe pliki które może posiadać każdy z modułów. Ilość plików na początku może przerażać, jednak zapewniam że gdy dobrze poznamy ten framework, konfiguracja stanie się bardzo prosta i intuicyjna. Generator stworzył nam domyślną konfigurację i na niej będziemy się opierać. Zmienimy jedynie 4 pliki.</p>
<h4>settings.xml</h4>
<p>Ustawiamy akcję Index modułu Notes jako domyślną.</p>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_49209999323d5">
<div class="synthi_header" style="font-weight:bold;"> XML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_49209999323d5').style.display='block';document.getElementById('plain_synthi_49209999323d5').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_49209999323d5">
<div class="synthi_header" style="font-weight:bold;"> XML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_49209999323d5').style.display='block';document.getElementById('styled_synthi_49209999323d5').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="xml" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;system_action</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;default&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;module<span style="font-weight: bold; color: black;">&gt;</span></span></span>Notes<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/module<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;action<span style="font-weight: bold; color: black;">&gt;</span></span></span>Index<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/action<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/system_action<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
<p>oraz włączamy komponent bazy danych:</p>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_49209999345c6">
<div class="synthi_header" style="font-weight:bold;"> XML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_49209999345c6').style.display='block';document.getElementById('plain_synthi_49209999345c6').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_49209999345c6">
<div class="synthi_header" style="font-weight:bold;"> XML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_49209999345c6').style.display='block';document.getElementById('styled_synthi_49209999345c6').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="xml" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;setting</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;use_database&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>true<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/setting<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
<h4>databases.xml</h4>
<p>Deklarujemy driver którego będziemy używać (w naszym przypadku PDO ale nic nie stoi na przeszkodzie abyś użył Propela, Doctrine lub cokolwiek innego) oraz dane potrzebne do nawiązania połączenia z bazą danych.</p>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_49209999361c7">
<div class="synthi_header" style="font-weight:bold;"> XML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_49209999361c7').style.display='block';document.getElementById('plain_synthi_49209999361c7').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_49209999361c7">
<div class="synthi_header" style="font-weight:bold;"> XML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_49209999361c7').style.display='block';document.getElementById('styled_synthi_49209999361c7').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="xml" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span> ?xml <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="font-weight: bold; color: black;">?&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;configurations</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://agavi.org/agavi/1.0/config&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>&nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;configuration<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;databases</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;pdo_mysql&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>&nbsp;&nbsp;&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;database</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;pdo_mysql&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;AgaviPdoDatabase&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dsn&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>mysql:host=localhost;dbname=agavi_application<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>root<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>pass<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/database<span style="font-weight: bold; color: black;">&gt;</span></span></span>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/databases<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/configuration<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/configurations<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
<h4>routing.xml</h4>
<p>Plik z drogami. Zadeklarowaliśmy 3 scieżki. Pierwsza zostanie wybrana, gdy adres będzie wyglądał np. tak:<br />
http://strona.pl/notes/123/html. Wykonana zostanie wtedy akcję ShowOne modułu Notes, przekazując parametr id o wartości 123. Druga pokaże nam formularz dodawania notki, a trzecia domyślną akcję.</p>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_492099993c811">
<div class="synthi_header" style="font-weight:bold;"> XML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_492099993c811').style.display='block';document.getElementById('plain_synthi_492099993c811').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_492099993c811">
<div class="synthi_header" style="font-weight:bold;"> XML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_492099993c811').style.display='block';document.getElementById('styled_synthi_492099993c811').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="xml" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span> ?xml <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="font-weight: bold; color: black;">?&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;configurations</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://agavi.org/agavi/1.0/config&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;configuration<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;routes<span style="font-weight: bold; color: black;">&gt;</span></span></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;route</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;note_one&quot;</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;^/note/(id:\d+).html$&quot;</span> <span style="color: #000066;">module</span>=<span style="color: #ff0000;">&quot;Notes&quot;</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;ShowOne&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;route</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;note_add&quot;</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;^/add.html$&quot;</span> <span style="color: #000066;">module</span>=<span style="color: #ff0000;">&quot;Notes&quot;</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;Add&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;route</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;^/$&quot;</span> <span style="color: #000066;">module</span>=<span style="color: #ff0000;">&quot;%actions.default_module%&quot;</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;%actions.default_action%&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/routes<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/configuration<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/configurations<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
<h4>output_types.xml</h4>
<p>W sekcji layouts, dodajemy jedną warstwę. Dekorator, czyli nasz &#8220;główny&#8221; szablon.</p>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_492099994216b">
<div class="synthi_header" style="font-weight:bold;"> XML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_492099994216b').style.display='block';document.getElementById('plain_synthi_492099994216b').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_492099994216b">
<div class="synthi_header" style="font-weight:bold;"> XML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_492099994216b').style.display='block';document.getElementById('styled_synthi_492099994216b').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="xml" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;layer</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;decorator&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;template&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>%core.app_dir%/templates/Master<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/layer<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
<h3>Model</h3>
<p>Pisanie aplikacji zaczniemy od modelu. Zaimplementujemy w nim metody które będą potrzebne dla akcji/widoków. Będą to metody: getRecent (zwrócenie ostatnich kilku notek), getById (zwrócenie notki o danym id) oraz save (zapis):</p>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_492099994506e">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_492099994506e').style.display='block';document.getElementById('plain_synthi_492099994506e').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_492099994506e">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_492099994506e').style.display='block';document.getElementById('styled_synthi_492099994506e').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="php" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt; ?php</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Notes_NotesModel <span style="color: #000000; font-weight: bold;">extends</span> ProjectBaseModel</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #0000ff;">$dbLayer</span> = <span style="color: #000000; font-weight: bold;">null</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> initialize<span style="color: #66cc66;">&#40;</span>AgaviContext <span style="color: #0000ff;">$context</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a> <span style="color: #0000ff;">$parameters</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parent::<span style="color: #006600;">initialize</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$context</span>, <span style="color: #0000ff;">$parameters</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">dbLayer</span> = <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">getContext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> -&gt; <span style="color: #006600;">getDatabaseConnection</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">dbLayer</span> -&gt; <a href="http://www.php.net/exec"><span style="color: #000066;">exec</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SET NAMES utf8&quot;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getById<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$id</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$stmt</span> = <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">dbLayer</span> -&gt; <span style="color: #006600;">prepare</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SELECT * FROM notes WHERE id = :id&quot;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$stmt</span> -&gt; <span style="color: #006600;">bindParam</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;id&quot;</span>, <span style="color: #0000ff;">$id</span>, PDO::<span style="color: #006600;">PARAM_INT</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$stmt</span> -&gt; <span style="color: #006600;">setFetchMode</span><span style="color: #66cc66;">&#40;</span>PDO::<span style="color: #006600;">FETCH_OBJ</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$stmt</span> -&gt; <span style="color: #006600;">execute</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$stmt</span> -&gt; <span style="color: #006600;">fetch</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getRecent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$stmt</span> = <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">dbLayer</span> -&gt; <span style="color: #006600;">prepare</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SELECT * FROM notes ORDER BY date DESC LIMIT 10&quot;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$stmt</span> -&gt; <span style="color: #006600;">setFetchMode</span><span style="color: #66cc66;">&#40;</span>PDO::<span style="color: #006600;">FETCH_OBJ</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$stmt</span> -&gt; <span style="color: #006600;">execute</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$stmt</span> -&gt; <span style="color: #006600;">fetchAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> save<span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a> <span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$stmt</span> = <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">dbLayer</span> -&gt; <span style="color: #006600;">prepare</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;INSERT INTO notes VALUES(NULL, :title, :intro, :text, NOW(), :author)&quot;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$stmt</span> -&gt; <span style="color: #006600;">execute</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
<p>Tak wygląda nasz model. Myślę że zbytnio nie ma co się rozpisywać, są to podstawowe operacje na baze danych używając PDO. </p>
<h3>Akcje</h3>
<p>Wygenerowane akcje mają obszerny komentarza. Warto go przeczytać i zapamiętać wskazówki w nim zawarte. Oprócz komentarza (po przeczytaniu możemy go wywalić ;) mamy jedną metodę: getDefaultViewName, zwraca ona domyślny widok który ma być wykonany jeżeli nie wskazano innego.</p>
<p>Najważniejszymi metodami akcji są metody executeRead oraz executeWrite. Są one wykonywane odpowiednio gdy wysłane są dane metodą GET i POST. Można zaimplementować jedną metodę - execute - w której ręcznie sprawdzali byśmy sobie skąd otrzymujemy dane. Nie jest to zalecane rozwiązanie jednak może zaistnieć sytuacja kiedy będziemy musieli z tej możliwości skorzystać. Wszystkie z tych 3 metod muszą zwrócić nazwę widoku który ma być wykonany. W przeciwnym wypadku nie zostanie wykonany żaden widok.</p>
<p>Jeżeli chodzi o naszą małą aplikację, a właściwie nasz jeden mały moduł to interesuje nas jedynie akcja Add. Inne akcje nie będą posiadały żadnej logiki. Będą jedynie zwracać widok, ten natomiast będzie prezentował dane pobrane od modelu.</p>
<p>Akcja Add domyślnie będzie uruchamiać widok Input, który będzie zawierał formularz. Jeżeli jednak zostaną przesłane jakieś dane metodą POST to zostanie wywołana metoda executeWrite.</p>
<p>Oto jak będzie wyglądać nasza akcja:</p>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_492099995815c">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_492099995815c').style.display='block';document.getElementById('plain_synthi_492099995815c').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_492099995815c">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_492099995815c').style.display='block';document.getElementById('styled_synthi_492099995815c').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="php" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt; ?php</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Notes_AddAction <span style="color: #000000; font-weight: bold;">extends</span> ProjectBaseAction</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeWrite<span style="color: #66cc66;">&#40;</span>AgaviRequestDataHolder <span style="color: #0000ff;">$rd</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$model</span> = <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">getContext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> -&gt; <span style="color: #006600;">getModel</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Notes&quot;</span>, <span style="color: #ff0000;">&quot;Notes&quot;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$model</span> -&gt; <span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rd</span> -&gt; <span style="color: #006600;">getParameter</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;note&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&#8216;Success&#8217;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getDefaultViewName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&#8216;Input&#8217;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
<p>Kod bardzo prosty. Pobranie modelu, następnie wywołanie metody save, podając jako argument tablicę z danymi z formularza ($rd jest obiektem typu AgaviRequestDataHolder, są tam przechowywane dane z requestu)</p>
<h3>Widoki</h3>
<p>Została nam ostania warstwa aplikacji, warstwa prezentacyjna czyli widok. W tym przypadku pomijamy widoku akcji Add, ponieważ nie potrzebujemy wciągać żadnych danych. Pokażemy jedynie formularz (Input) lub wiadomość o tym że dodano wiadomość (Success). Tak będą natomiast będą wyglądać widoki:</p>
<h4>IndexSuccessView</h4>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_49209999626bf">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_49209999626bf').style.display='block';document.getElementById('plain_synthi_49209999626bf').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_49209999626bf">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_49209999626bf').style.display='block';document.getElementById('styled_synthi_49209999626bf').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="php" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt; ?php</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Notes_IndexSuccessView <span style="color: #000000; font-weight: bold;">extends</span> ProjectBaseView</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeHtml<span style="color: #66cc66;">&#40;</span>AgaviRequestDataHolder <span style="color: #0000ff;">$rd</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parent::<span style="color: #006600;">setupHtml</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rd</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$model</span> = <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">getContext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> -&gt; <span style="color: #006600;">getModel</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Notes&quot;</span>, <span style="color: #ff0000;">&quot;Notes&quot;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;notes&quot;</span>, <span style="color: #0000ff;">$model</span> -&gt; <span style="color: #006600;">getRecent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
<h4>ShowOneSuccessView</h4>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_492099996a11e">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_492099996a11e').style.display='block';document.getElementById('plain_synthi_492099996a11e').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_492099996a11e">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_492099996a11e').style.display='block';document.getElementById('styled_synthi_492099996a11e').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="php" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt; ?php</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Notes_ShowOneSuccessView <span style="color: #000000; font-weight: bold;">extends</span> ProjectBaseView</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeHtml<span style="color: #66cc66;">&#40;</span>AgaviRequestDataHolder <span style="color: #0000ff;">$rd</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parent::<span style="color: #006600;">setupHtml</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rd</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$model</span> = <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">getContext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> -&gt; <span style="color: #006600;">getModel</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Notes&quot;</span>, <span style="color: #ff0000;">&quot;Notes&quot;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp;&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;note&quot;</span>, <span style="color: #0000ff;">$model</span> -&gt; <span style="color: #006600;">getById</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rd</span> -&gt; <span style="color: #006600;">getParameter</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
<p>Są one prawie takie same. Różnią się one jedynie metodą modelu którą wykonujemy. W widoku ShowOne pobieramy z modelu jedną notkę o id którego wartość bierzemy z requestu, tam natomiast trafiło z routera, czyli z adresu url :)</p>
<p>Pozostało nam już tylko napisanie szablonów. Zacznijmy od głównego szablonu, czyli Master.php który musimy utworzyć w app/templates:</p>
<h4>app/templates/Master.php</h4>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_4920999972bf1">
<div class="synthi_header" style="font-weight:bold;"> HTML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4920999972bf1').style.display='block';document.getElementById('plain_synthi_4920999972bf1').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_4920999972bf1">
<div class="synthi_header" style="font-weight:bold;"> HTML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4920999972bf1').style.display='block';document.getElementById('styled_synthi_4920999972bf1').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="html" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a> !DOCTYPE html PUBLIC <span style="color: #ff0000;">&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span> <span style="color: #ff0000;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html</span></a> xmlns=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span> xml:<span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;pl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #009900;"><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">&lt;title&gt;</span></a></span>Notki<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;content-type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;content-language&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;pl&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></a></span> </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #009900;"><a href="http://december.com/html/4/element/base.html"><span style="color: #000000; font-weight: bold;">&lt;base</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;&lt;?php echo $ro-&gt;</span>getBaseHref(); ?&gt;&quot; /&gt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;">&lt;/base&gt;</span><span style="color: #009900;">&lt;/head&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;">&lt;body&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt; ?php echo $inner; ?&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;">&lt;/body&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;">&lt;/html&gt;</span> </span></div>
</li>
</ol>
</div>
</div>
<p>Ustawiając Master.php jako dekorator, wszystko co zwróci widok dane akcji (html), będzie później dostępne poprzez zmienną $inner. Szkielet strony wtedy trzymamy w Master.php a w miejscu, gdzie treść będzie sie zmieniać wyświetlamy zawartość $inner.</p>
<h4>IndexSuccess.php</h4>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_4920999980e44">
<div class="synthi_header" style="font-weight:bold;"> HTML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4920999980e44').style.display='block';document.getElementById('plain_synthi_4920999980e44').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_4920999980e44">
<div class="synthi_header" style="font-weight:bold;"> HTML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4920999980e44').style.display='block';document.getElementById('styled_synthi_4920999980e44').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="html" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">&lt;h1&gt;</span></a></span>Notki<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></a></span><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;&lt;?php echo $ro -&gt;</span> gen(&quot;note_add&quot;); ?&gt;&quot;&gt;Dodaj<span style="color: #009900;">&lt;/a&gt;</span><span style="color: #009900;">&lt;/p&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;ul&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt; ?php foreach($template['notes'] as $note){ ?&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;li&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;div&gt;</span><span style="color: #009900;">&lt;a href=&quot;</span><span style="color: #000000; font-weight: bold;">&lt;</span></a>?php $ro -<span style="color: #000000; font-weight: bold;">&gt;</span></a></span> gen(&quot;note_one&quot;, array(&quot;id&quot; =&gt; $note -&gt; id)); ?&gt;&quot;&gt;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a> ?php echo $note -<span style="color: #000000; font-weight: bold;">&gt;</span></a></span> title; ?&gt;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a> ?php echo $note -<span style="color: #000000; font-weight: bold;">&gt;</span></a></span> intro; ?&gt;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a> ?php <span style="color: #66cc66;">&#125;</span> ?<span style="color: #000000; font-weight: bold;">&gt;</span></a></span> </div>
</li>
</ol>
</div>
</div>
<h4>ShowOneSuccess.php</h4>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_492099998f2c7">
<div class="synthi_header" style="font-weight:bold;"> HTML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_492099998f2c7').style.display='block';document.getElementById('plain_synthi_492099998f2c7').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_492099998f2c7">
<div class="synthi_header" style="font-weight:bold;"> HTML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_492099998f2c7').style.display='block';document.getElementById('styled_synthi_492099998f2c7').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="html" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a> ?php $note = $template<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&#8216;note&#8217;</span><span style="color: #66cc66;">&#93;</span>; ?<span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/h2.html"><span style="color: #000000; font-weight: bold;">&lt;h2&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a> ?php echo $note -<span style="color: #000000; font-weight: bold;">&gt;</span></a></span> title; ?&gt;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h2&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div&gt;</span></a></span>&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a> ?php echo $note -<span style="color: #000000; font-weight: bold;">&gt;</span></a></span> intro; ?&gt;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a> ?php echo $note -<span style="color: #000000; font-weight: bold;">&gt;</span></a></span> text; ?&gt;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a> ?php echo $note -<span style="color: #000000; font-weight: bold;">&gt;</span></a></span> author; ?&gt; / <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a> ?php echo $note -<span style="color: #000000; font-weight: bold;">&gt;</span></a></span> date; ?&gt;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span>&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
<h4>AddInput.php</h4>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_492099999eef6">
<div class="synthi_header" style="font-weight:bold;"> HTML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_492099999eef6').style.display='block';document.getElementById('plain_synthi_492099999eef6').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_492099999eef6">
<div class="synthi_header" style="font-weight:bold;"> HTML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_492099999eef6').style.display='block';document.getElementById('styled_synthi_492099999eef6').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="html" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/h2.html"><span style="color: #000000; font-weight: bold;">&lt;h2&gt;</span></a></span>Dodaj notkę<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h2&gt;</span></span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">&lt;form</span></a> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;&lt;?php echo $ro -&gt;</span> gen(&quot;note_add&quot;); ?&gt;&quot; method=&quot;post&quot;&gt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;">&lt;div&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;label for=&quot;</span><span style="color: #000066;">title</span><span style="color: #ff0000;">&quot;&gt;</span>Tytuł<span style="color: #009900;">&lt;/label&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;input type=&quot;</span><span style="color: #000066;">text</span><span style="color: #ff0000;">&quot; name=&quot;</span>note<span style="color: #66cc66;">&#91;</span><span style="color: #000066;">title</span><span style="color: #66cc66;">&#93;</span><span style="color: #ff0000;">&quot; id=&quot;</span><span style="color: #000066;">title</span><span style="color: #ff0000;">&quot; /&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;">&lt;/div&gt;</span> </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;">&lt;div&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;label for=&quot;</span>intro<span style="color: #ff0000;">&quot;&gt;</span>Wstęp<span style="color: #009900;">&lt;/label&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;textarea name=&quot;</span>note<span style="color: #66cc66;">&#91;</span>intro<span style="color: #66cc66;">&#93;</span><span style="color: #ff0000;">&quot; id=&quot;</span>intro<span style="color: #ff0000;">&quot;&gt;</span><span style="color: #009900;">&lt;/textarea&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;">&lt;/div&gt;</span> </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;">&lt;div&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;label for=&quot;</span><span style="color: #000066;">text</span><span style="color: #ff0000;">&quot;&gt;</span>Treść<span style="color: #009900;">&lt;/label&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;textarea name=&quot;</span>note<span style="color: #66cc66;">&#91;</span><span style="color: #000066;">text</span><span style="color: #66cc66;">&#93;</span><span style="color: #ff0000;">&quot; id=&quot;</span><span style="color: #000066;">text</span><span style="color: #ff0000;">&quot;&gt;</span><span style="color: #009900;">&lt;/textarea&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;">&lt;/div&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;">&lt;div&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;label for=&quot;</span>author<span style="color: #ff0000;">&quot;&gt;</span>Autor<span style="color: #009900;">&lt;/label&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;input type=&quot;</span><span style="color: #000066;">text</span><span style="color: #ff0000;">&quot; name=&quot;</span>note<span style="color: #66cc66;">&#91;</span>author<span style="color: #66cc66;">&#93;</span><span style="color: #ff0000;">&quot; id=&quot;</span>author<span style="color: #ff0000;">&quot; /&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;">&lt;/div&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;">&lt;div&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;input type=&quot;</span>submit<span style="color: #ff0000;">&quot; value=&quot;</span>Dodaj<span style="color: #ff0000;">&quot; /&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;">&lt;/div&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;/form&gt;</span> </span></div>
</li>
</ol>
</div>
</div>
<h4>AddSuccess.php</h4>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_49209999ae9e7">
<div class="synthi_header" style="font-weight:bold;"> HTML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_49209999ae9e7').style.display='block';document.getElementById('plain_synthi_49209999ae9e7').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_49209999ae9e7">
<div class="synthi_header" style="font-weight:bold;"> HTML <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_49209999ae9e7').style.display='block';document.getElementById('styled_synthi_49209999ae9e7').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="html" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></a></span>Dodano notkę!<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
<p>Nad szablonami myślę że nie ma za bardzo co się rozwodzić. Zwykły HTML, wyświetlający dane otrzymane z widoku.</p>
<h3>Zakończenie</h3>
<p>W kilku szybkich krokach, nie zagłębiając się w szczegóły, stworzyliśmy bardzo prostą aplikację. Coś w stylu &#8220;Jak napisać bloga w 15 minut&#8221; używając mojego kochanego frameworka ;) Notka ta miała na celu bardziej zachęcić do zainteresowania się Agavi, niż szczegółowo opisać cały framework. Wszystko w swoim czasie ;)</p>
<p>Polecam przejrzeć jeszcze raz <a href="./sources/agavi_application.zip">kod aplikacji</a> (teoretycznie powinna ona działać, po uruchomieniu ;) w aby lepiej zrozumieć zasadę działania. Warto również zajrzeć do przykładowej aplikacji znajdującej się w paczce Agavi w folderze samples.</p>
]]></content:encoded>
			<wfw:commentRss>http://strzalek.net/blog/5/agavi-wprowadzenie/feed</wfw:commentRss>
		<feedburner:origLink>http://strzalek.net/blog/5/agavi-wprowadzenie</feedburner:origLink></item>
		<item>
		<title>Doctrine - ORM dla PHP</title>
		<link>http://feeds.feedburner.com/~r/strzalek-devblog/~3/282314138/doctrine-orm-dla-php</link>
		<comments>http://strzalek.net/blog/4/doctrine-orm-dla-php#comments</comments>
		<pubDate>Fri, 02 May 2008 19:29:06 +0000</pubDate>
		<dc:creator>Strzałek</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[doctrine]]></category>

		<category><![CDATA[orm]]></category>

		<guid isPermaLink="false">http://strzalek.net/blog/?p=4</guid>
		<description><![CDATA[Po pewnym czasie obcowania z bazą danych, ciągłe pisanie zapytań oraz ich przetwarzanie może stać się strasznie męczące. Dodatkowo pojawia się problemu z kompatybilnością baz danych
Na przeciw temu wszystkiemu wychodzą ORMy. ORM czyli Object-Relational Mapping jest to rozwiązanie w którym dane są mapowane i zwracane w postaci obiektów. Powstało kilkanaście rozwiązań ORM dla PHP. Najpopularniejsze [...]]]></description>
			<content:encoded><![CDATA[<p>Po pewnym czasie obcowania z bazą danych, ciągłe pisanie zapytań oraz ich przetwarzanie może stać się strasznie męczące. Dodatkowo pojawia się problemu z kompatybilnością baz danych</p>
<p>Na przeciw temu wszystkiemu wychodzą ORMy. <a href="http://pl.wikipedia.org/wiki/ORM">ORM</a> czyli Object-Relational Mapping jest to rozwiązanie w którym dane są mapowane i zwracane w postaci obiektów. Powstało kilkanaście rozwiązań ORM dla PHP. Najpopularniejsze to <a href="http://propel.phpdb.org/">Propel</a> oraz <a href="http://www.phpdoctrine.org/">Doctrine</a>, osobiście w projektach używam tego drugiego i tą notką postaram się przybliżyć wam użycie tego ORM.<br />
<span id="more-4"></span></p>
<h3>Rekordy</h3>
<p>Przed napisaniem pierwszego zapytania musimy stworzyć wcześniej rekordów. Stwórzmy sobie bazę danych posiadającą 3 tabele: categories (id, name), companies (id, name) oraz products (id, name, description, price, company, category) na której będziemy operować bawiąc się Doctrine. Baza ta będzie przechowywać produkty, każdy z produktów może znajdować się w jednej kategorii oraz może być stworzony przez jedną firmę.</p>
<h4>models/Category.php</h4>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_4920999ab6745">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4920999ab6745').style.display='block';document.getElementById('plain_synthi_4920999ab6745').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_4920999ab6745">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4920999ab6745').style.display='block';document.getElementById('styled_synthi_4920999ab6745').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="php" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt; ?php</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Category <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Record</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setTableDefinition<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">setTableName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;categories&quot;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">hasColumn</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;name&quot;</span>, <span style="color: #ff0000;">&quot;string&quot;</span>, <span style="color: #cc66cc;">45</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUp<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">hasMany</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Product as Products&quot;</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;local&quot;</span> =&gt; <span style="color: #ff0000;">&quot;id&quot;</span>, <span style="color: #ff0000;">&quot;foreign&quot;</span> =&gt; <span style="color: #ff0000;">&quot;category&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
<h4>models/Company.php</h4>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_4920999ac33bd">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4920999ac33bd').style.display='block';document.getElementById('plain_synthi_4920999ac33bd').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_4920999ac33bd">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4920999ac33bd').style.display='block';document.getElementById('styled_synthi_4920999ac33bd').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="php" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt; ?php</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Company <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Record</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setTableDefinition<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">setTableName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;companies&quot;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">hasColumn</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;name&quot;</span>, <span style="color: #ff0000;">&quot;string&quot;</span>, <span style="color: #cc66cc;">45</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUp<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">hasMany</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Product as Products&quot;</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;local&quot;</span> =&gt; <span style="color: #ff0000;">&quot;id&quot;</span>, <span style="color: #ff0000;">&quot;foreign&quot;</span> =&gt; <span style="color: #ff0000;">&quot;company&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
<h4>models/Product.php</h4>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_4920999aced3b">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4920999aced3b').style.display='block';document.getElementById('plain_synthi_4920999aced3b').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_4920999aced3b">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4920999aced3b').style.display='block';document.getElementById('styled_synthi_4920999aced3b').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="php" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt; ?php</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Product <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Record</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setTableDefinition<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">setTableName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;products&quot;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">hasColumn</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;name&quot;</span>, <span style="color: #ff0000;">&quot;string&quot;</span>, <span style="color: #cc66cc;">45</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">hasColumn</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;description&quot;</span>, <span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">hasColumn</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;price&quot;</span>, <span style="color: #ff0000;">&quot;decimal&quot;</span>, <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">hasColumn</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;category&quot;</span>, <span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">hasColumn</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;company&quot;</span>, <span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUp<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">hasOne</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Category&quot;</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;local&quot;</span> =&gt; <span style="color: #ff0000;">&quot;category&quot;</span>, <span style="color: #ff0000;">&quot;foreign&quot;</span> =&gt; <span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">hasOne</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Company&quot;</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;local&quot;</span> =&gt; <span style="color: #ff0000;">&quot;company&quot;</span>, <span style="color: #ff0000;">&quot;foreign&quot;</span> =&gt; <span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
<p>Tak wyglądają zadeklarowane rekordy. Każdy rekord musi dziedziczyć po Doctrine_Record. Pierwszą rzeczą jaką trzeba zrobić zrobić jest implementacja metody setTableDefinition, w której ustawiamy nazwę tabeli oraz deklarujemy kolumny jakie posiada (pole id jest deklarowane domyślnie). Następną rzeczą którą możemy uczynić jest ustawienie relacji zachodzących z rekordem. Do dyspozycji mamy 3 typu relacji: one-to-one (hasOne), one-to-many (hasMany) oraz many-to-many (o tej relacji kiedy indziej).</p>
<p>Wszystko pięknie, jednak gdy mamy do czynienia z dużą bazą danych gdzie operujemy na 20-30 tabelach, stworzenie rekordów dla bazy może być czasochłonne. Zresztą &#8220;przepisanie&#8221; struktury nawet dla 10 już jest męczące ;) Tutaj przychodzi z pomocą generator który udostępnia nam Doctrine. Może on stworzyć za nas wszystkie rekordy, a jego użycie sprowadza się do połączenia się z bazą danych oraz wywołania metody generateModelsFromDb, podając folder do którego mają być wygenerowane rekordy:</p>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_4920999ae7c8f">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4920999ae7c8f').style.display='block';document.getElementById('plain_synthi_4920999ae7c8f').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_4920999ae7c8f">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4920999ae7c8f').style.display='block';document.getElementById('styled_synthi_4920999ae7c8f').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="php" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt; ?php</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/set_time_limit"><span style="color: #000066;">set_time_limit</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Dołączenie główengo pliku Doctrine.</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;./lib/Doctrine.php&#8217;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Zarejestrowanie autoloadera Doctrine.</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">spl_autoload_register<span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;Doctrine&#8217;</span>, <span style="color: #ff0000;">&#8216;autoload&#8217;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Ustawienie połączenia</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Doctrine_Manager::<span style="color: #006600;">connection</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;mysql://root:pass@localhost/doctrine&#8217;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Wywołanie generatora</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Doctrine::<span style="color: #006600;">generateModelsFromDb</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;models&#8217;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//W folderze models mamy już gotowe do użycia rekordy</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
<h3>Podstawowe operacje</h3>
<p>Posiadając rekordy na których będziemy operować możemy przystąpić do działania. Zacznijmy od wypełnienia naszej bazy jakimiś danymi, by później móc wykonywać jakieś zapytania.</p>
<p>Użycie rekordów jest bardzo proste. Sprowadza się do stworzenia obiektu rekordu, następnie wypełnienia go danymi i wywołania metody save. Dodajmy pierwszy produkt:</p>
<h4>Dodawanie</h4>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:none;" id ="plain_synthi_4920999af29ad">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4920999af29ad').style.display='block';document.getElementById('plain_synthi_4920999af29ad').style.display='none';return false">Show Styled Code</a>]:</span></div>
</div>
<div class="synthi_code" style="border: 1px solid #cccccc; padding: 3px; font-size: 12px; margin: 10px 8px; overflow: auto;  white-space:nowrap; display:block;" id ="styled_synthi_4920999af29ad">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4920999af29ad').style.display='block';document.getElementById('styled_synthi_4920999af29ad').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="php" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt; ?php</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/set_time_limit"><span style="color: #000066;">set_time_limit</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Dołączenie główengo pliku Doctrine.</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;./lib/Doctrine.php&#8217;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Zarejestrowanie autoloadera Doctrine.</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">spl_autoload_register<span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;Doctrine&#8217;</span>, <span style="color: #ff0000;">&#8216;autoload&#8217;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Załadowanie wygenerowanych rekordów które znajdują się w folderze models</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Doctrine::<span style="color: #006600;">loadModels</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;models&#8217;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #808080; font-style: italic;">//Ustawienie połączenia</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #0000ff;">$conn</span> = Doctrine_Manager::<span style="color: #006600;">connection</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;mysql://root:pass@localhost/doctrine&#8217;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #0000ff;">$product</span> = <span style="color: #000000; font-weight: bold;">new</span> Product<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">name</span> = <span style="color: #ff0000;">&quot;Zend Studio Professional Edition&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">description</span> = <span style="color: #ff0000;">&quot;IDE dla PHP&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">price</span> = <span style="color: #cc66cc;">1500.00</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">Company</span> -&gt; <span style="color: #006600;">name</span> = <span style="color: #ff0000;">&quot;Zend Technologies&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #0