<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><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>Fri, 10 Apr 2009 15:46:28 +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>XML - morze możliwości - XPath, XPointer, XInclude</title>
		<link>http://feedproxy.google.com/~r/strzalek-devblog/~3/06zXVmsLoZU/xml-morze-mozliwosci-xpath-xpointer-xinclude</link>
		<comments>http://strzalek.net/blog/7/xml-morze-mozliwosci-xpath-xpointer-xinclude#comments</comments>
		<pubDate>Thu, 27 Nov 2008 20:03:24 +0000</pubDate>
		<dc:creator>Strzałek</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[xinclude]]></category>

		<category><![CDATA[xpath]]></category>

		<category><![CDATA[xpointer]]></category>

		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://strzalek.net/blog/?p=7</guid>
		<description><![CDATA[Często odbywają się dyskusje dotyczące formatu w jakim przechowywać konfiguracja aplikacji. Najczęściej wybierane sposoby to pliki INI, YAML oraz XML. Za najlepsze rozwiązanie uważam wykorzystanie XML&#8217;a.
Główną zaletą XML jest jego popularność oraz szereg standartów które znacznie usprawniają prace. Struktury XML są bardzo łatwo rozszerzalne poprzez XInclude. Walidację takiego pliku można bardzo szybko rozwiązać tworząc plik [...]]]></description>
			<content:encoded><![CDATA[<p>Często odbywają się dyskusje dotyczące formatu w jakim przechowywać konfiguracja aplikacji. Najczęściej wybierane sposoby to pliki <a href="http://pl.wikipedia.org/wiki/INI">INI</a>, <a href="http://pl.wikipedia.org/wiki/YAML">YAML</a> oraz <a href="http://pl.wikipedia.org/wiki/XML_Schema">XML</a>. Za najlepsze rozwiązanie uważam wykorzystanie XML&#8217;a.</p>
<p>Główną zaletą XML jest jego popularność oraz szereg standartów które znacznie usprawniają prace. Struktury XML są bardzo łatwo rozszerzalne poprzez <a href="http://www.w3.org/TR/xinclude/">XInclude</a>. Walidację takiego pliku można bardzo szybko rozwiązać tworząc plik XSD, natomiast jeżeli potrzebujemy ładnej prezentacji zawartości, wystarczy stworzyć plik XSLT oraz napisać kilkadziesiąt linijek.<br />
<span id="more-7"></span></p>
<h3>Przykładowy plik XML</h3>
<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_4a5f4d6ff01bd">
<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_4a5f4d6ff01bd').style.display='block';document.getElementById('plain_synthi_4a5f4d6ff01bd').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_4a5f4d6ff01bd">
<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_4a5f4d6ff01bd').style.display='block';document.getElementById('styled_synthi_4a5f4d6ff01bd').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;adress</span> -book<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;presons<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1&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;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Jan<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Kowlaski<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>jan-kowalski@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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;/person<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;2&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;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Piotr<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Nowak<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>piotr-nowak@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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;/person<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1&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;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Paweł<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Kwiatkowski<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>jan-kowalski@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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;/person<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;/presons<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;/adress<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
<p><a href="http://www.w3.org/TR/xpath">XPath</a> jest językiem używanym do lokalizacji oraz pozyskiwania informacji z drzewa XML. Język ten jest również potrzebny podczas używania XPointer oraz XSLT</p>
<p>Do przetwarzania XML&#8217;a będziemy używać rozszerzenia <a href="http://pl2.php.net/manual/pl/book.dom.php">DOM</a> dla PHP.</p>
<p>Zacznijmy od podstawowego wyrażenia xpath. Pobierzemy wszystkie nazwiska z naszej książki adresowej:</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_4a5f4d7002970">
<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_4a5f4d7002970').style.display='block';document.getElementById('plain_synthi_4a5f4d7002970').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_4a5f4d7002970">
<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_4a5f4d7002970').style.display='block';document.getElementById('styled_synthi_4a5f4d7002970').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: #0000ff;">$dom</span> = <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<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;"><span style="color: #0000ff;">$dom</span>-&gt;<span style="color: #006600;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;address-book.xml&#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: #0000ff;">$xpath</span> = <span style="color: #000000; font-weight: bold;">new</span> DOMXPath<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$dom</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: #0000ff;">$persons</span> = <span style="color: #0000ff;">$xpath</span>-&gt;<span style="color: #006600;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/address-book/persons/person/lastname&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;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$persons</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$person</span><span style="color: #66cc66;">&#41;</span> <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; <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$person</span>-&gt;<span style="color: #006600;">nodeValue</span>.<span style="color: #ff0000;">&quot;&lt;br /&gt;&quot;</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>
<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_4a5f4d700881a">
<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_4a5f4d700881a').style.display='block';document.getElementById('plain_synthi_4a5f4d700881a').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_4a5f4d700881a">
<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_4a5f4d700881a').style.display='block';document.getElementById('styled_synthi_4a5f4d700881a').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;">Kowlaski
</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Nowak
</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Kwiatkowski
</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Jankowski</div>
</li>
</ol>
</div>
</div>
<p>Do wykonywania operacji korzystając z XPath służy klasa <a href="http://pl.php.net/manual/pl/class.domxpath.php">DOMXPath</a>. Tworząc egzemplarz tej klasy przekazujemy obiekt DOM na którym chcemy operować, następnie używając metody query która zwraca to o co prosiliśmy.</p>
<p>A o co prosiliśmy i jak prosić? W przykładzie powyżej napisaliśmy bardzo proste wyrażenie, które zwróciło nam tylko nazwiska (lastname) osób w książce. Poszczególne poziomy w dokumencie XML oddzielane są znakiem /. Jezeli zapytanie zaczyna się od slasha oznacza to że wyszukiwanie ma zacząć się od najwyższego elementu.</p>
<p>Używając XPath możemy pisać bardziej szczególowe zapytania. Wybrać nazwisko osoby o numerze id równym 1:</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_4a5f4d7008d51">
<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_4a5f4d7008d51').style.display='block';document.getElementById('plain_synthi_4a5f4d7008d51').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_4a5f4d7008d51">
<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_4a5f4d7008d51').style.display='block';document.getElementById('styled_synthi_4a5f4d7008d51').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;">/address-book/persons/person[@id='1']/lastname </div>
</li>
</ol>
</div>
</div>
<p>Dodający przy person nawias kwadratowy ograniczyliśmy wyszukiwanie tylko do elementów person które posiadają atrybut id o wartości równej 1. Znak @ przed id oznacza że uwzględniamy atrybuty nie elementy.</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_4a5f4d70095fe">
<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_4a5f4d70095fe').style.display='block';document.getElementById('plain_synthi_4a5f4d70095fe').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_4a5f4d70095fe">
<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_4a5f4d70095fe').style.display='block';document.getElementById('styled_synthi_4a5f4d70095fe').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;">/address-book/persons/person[firstname='Paweł' and city='Warszawa']/lastname </div>
</li>
</ol>
</div>
</div>
<p>Powyższe zapytanie zwróci nam nazwiska osób których imię to Paweł oraz miejsce zamieszkania to Warszawa. W tym zapytanie nie używaliśmy znaku @ ponieważ interesowały nas elementy a nie atyrbuy.</p>
<p>Przedstawiłem tutaj podstawowe sposoby które najczęściej są używane podczas korzystanie z XPath. Po więcej informacji zapraszam do <a href="http://www.w3.org/TR/xpath">dokumentacji XPath</a>.</p>
<h3>XInclude</h3>
<h4>XPointer</h4>
<p>XPointer jest rozszerzeniem XPath i używa jego składni. Jest to język do adresowania fragmentów dokumentów XML. Został przewidziany do stosowania w adresach URI.</p>
<p>Przykładowe wyrażenia XPath używając XPointer wyglądają następująco:</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_4a5f4d700a05d">
<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_4a5f4d700a05d').style.display='block';document.getElementById('plain_synthi_4a5f4d700a05d').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_4a5f4d700a05d">
<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_4a5f4d700a05d').style.display='block';document.getElementById('styled_synthi_4a5f4d700a05d').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;">xpointer(/address-book/persons/person[@id='1']/lastname) </div>
</li>
</ol>
</div>
</div>
<p>Wspomniałem o używaniu w adresach URI. Tak przykładowo by wyglądało wyrażenie jako fragment URI:</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_4a5f4d700a727">
<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_4a5f4d700a727').style.display='block';document.getElementById('plain_synthi_4a5f4d700a727').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_4a5f4d700a727">
<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_4a5f4d700a727').style.display='block';document.getElementById('styled_synthi_4a5f4d700a727').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;">http://www.example.com/address-book.xml#xpointer(/address-book/persons/person[@id='1']/lastname)</div>
</li>
</ol>
</div>
</div>
<h4>XInclude</h4>
<p>XInclude jest standartem który pozwala nam dołączać zewnętrzne dokumenty lub ich fragmnety do pliku XML. XInclude zawiera się w przestrzeni nazw http://www.w3.org/2001/XInclude. W tym namespace mamy dwa elementy zakładając że zadeklarujemy prefix xi będzie to xi:include oraz xi:fallback. Pierwszy z nich określa lokalizacje jednostki którą chcemy dołączyć - może być to mały zakres XML&#8217;a wybrany XPath&#8217;em lub cały plik. Może się zdarzyć że XInclude zwróci błąd. Plik lub wybrany zakres który chcemy dołączyć może nie istnieć. Aby osłużyć błąd XInclude oferuje element xi:fallback.</p>
<p>Rozszerzmy naszą książkę adresową o grupy. Mając wiele konkatków w pewnym momencie dobrze by było je jakoś uporządkować.</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_4a5f4d700ac5a">
<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_4a5f4d700ac5a').style.display='block';document.getElementById('plain_synthi_4a5f4d700ac5a').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_4a5f4d700ac5a">
<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_4a5f4d700ac5a').style.display='block';document.getElementById('styled_synthi_4a5f4d700ac5a').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;address</span> -book<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;persons<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1&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;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Jan<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Kowlaski<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>jan-kowalski@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Warszawa<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<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;/person<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;2&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;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Piotr<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Nowak<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>piotr-nowak@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Kraków<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<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;/person<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;3&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;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Paweł<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Kwiatkowski<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>pawel-kwiatkowski@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Warszawa<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<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;/person<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;4&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;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Paweł<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Jankowski<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>robert-jankowski@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Poznań<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<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;/person<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;/persons<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;</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;groups<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;group</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Znajomi&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;persons<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;2&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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Piotr<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Nowak<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>piotr-nowak@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Kraków<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<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;/person<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;3&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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Paweł<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Kwiatkowski<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>pawel-kwiatkowski@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Warszawa<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<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;/person<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;/persons<span style="font-weight: bold; color: black;">&gt;</span></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; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/group<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;</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;group</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Praca&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;persons<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1&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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Jan<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Kowlaski<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>jan-kowalski@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Warszawa<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<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;/person<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;4&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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Paweł<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Jankowski<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>robert-jankowski@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Poznań<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<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;/person<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;/persons<span style="font-weight: bold; color: black;">&gt;</span></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; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/group<span style="font-weight: bold; color: black;">&gt;</span></span></span>&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; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/groups<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;</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;/address<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
<p>Nie trudno zauważyć że takie rozwiązanie jest kłopotliwe. Gdy ktoś zmieni numer będziemy musieli zmieniać ten numer w kilku miejscach.</p>
<p>Problem ten możemy rozwiązać właśnie dzięki XInclude. Zamiast posiadać te same wpisy kilka razy, będzie je dołączać na podstawie numeru ID.</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_4a5f4d701d31e">
<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_4a5f4d701d31e').style.display='block';document.getElementById('plain_synthi_4a5f4d701d31e').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_4a5f4d701d31e">
<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_4a5f4d701d31e').style.display='block';document.getElementById('styled_synthi_4a5f4d701d31e').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;address</span> -book xmlns:<span style="color: #000066;">xi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XInclude&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;persons<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1&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;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Jan<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Kowlaski<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>jan-kowalski@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Warszawa<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<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;/person<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;2&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;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Piotr<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Nowak<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>piotr-nowak@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Kraków<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<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;/person<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;3&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;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Paweł<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Kwiatkowski<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>pawel-kwiatkowski@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Warszawa<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<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;/person<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;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;4&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;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Paweł<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Jankowski<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>robert-jankowski@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Poznań<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<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;/person<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;/persons<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;</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;groups<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;group</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Znajomi&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;persons<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;xi</span> :include <span style="color: #000066;">xpointer</span>=<span style="color: #ff0000;">&quot;xpointer(/address-book/persons/person[@id='1'])&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;xi</span> :include <span style="color: #000066;">xpointer</span>=<span style="color: #ff0000;">&quot;xpointer(/address-book/persons/person[@id='4'])&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;/persons<span style="font-weight: bold; color: black;">&gt;</span></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; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/group<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;</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;group</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Praca&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;persons<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;xi</span> :include <span style="color: #000066;">xpointer</span>=<span style="color: #ff0000;">&quot;xpointer(/address-book/persons/person[@id='3'])&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;xi</span> :include <span style="color: #000066;">xpointer</span>=<span style="color: #ff0000;">&quot;xpointer(/address-book/persons/person[@id='4'])&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;/persons<span style="font-weight: bold; color: black;">&gt;</span></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; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/group<span style="font-weight: bold; color: black;">&gt;</span></span></span>&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; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/groups<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;</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;/address<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
<p>Przetwórzmy teraz ten plik używając PHP i DOM:</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_4a5f4d702c391">
<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_4a5f4d702c391').style.display='block';document.getElementById('plain_synthi_4a5f4d702c391').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_4a5f4d702c391">
<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_4a5f4d702c391').style.display='block';document.getElementById('styled_synthi_4a5f4d702c391').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: #0000ff;">$dom</span> = <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<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;"><span style="color: #0000ff;">$dom</span>-&gt;<span style="color: #006600;">preserverWhiteSpace</span> = <span style="color: #000000; font-weight: bold;">true</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$dom</span>-&gt;<span style="color: #006600;">formatOutput</span> = <span style="color: #000000; font-weight: bold;">true</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: #0000ff;">$dom</span>-&gt;<span style="color: #006600;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;address-book.xml&#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: #0000ff;">$dom</span>-&gt;<span style="color: #006600;">xinclude</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;"><span style="color: #0000ff;">$dom</span>-&gt;<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;adress-book-xinclude.xml&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;</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>Za XInclude w klasie odpowiedzialna jest metoda xinclude(). Na końcu zapisaliśmy zawartość w nowym pliku żeby móc sprawdzić czy to rzeczywiście działa. Otwierając plik powinniśmy zobaczyć zamiast wpisów xi:include, dołączone właściwe watrości.</p>
<p>Nasza książka może się rozrosnąć a trzymanie wszystkiego w jednym pliku może stać się nie wygodne. A co gdybyśmy chcieli trzymać grupy kontaktów w odzielnym pliku, np.: address-book-groups.xml?</p>
<p>Zawartość pliku wyglądała by wtedy następująco:</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_4a5f4d7030b53">
<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_4a5f4d7030b53').style.display='block';document.getElementById('plain_synthi_4a5f4d7030b53').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_4a5f4d7030b53">
<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_4a5f4d7030b53').style.display='block';document.getElementById('styled_synthi_4a5f4d7030b53').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;address</span> -book xmlns:<span style="color: #000066;">xi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XInclude&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;groups<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;group</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Znajomi&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;persons<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;xi</span> :include <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;address-book.xml&quot;</span> <span style="color: #000066;">xpointer</span>=<span style="color: #ff0000;">&quot;xpointer(/address-book/persons/person[@id='1'])&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;xi</span> :include <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;address-book.xml&quot;</span> <span style="color: #000066;">xpointer</span>=<span style="color: #ff0000;">&quot;xpointer(/address-book/persons/person[@id='4'])&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;/persons<span style="font-weight: bold; color: black;">&gt;</span></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; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/group<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;</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;group</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Praca&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;persons<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;xi</span> :include <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;address-book.xml&quot;</span> <span style="color: #000066;">xpointer</span>=<span style="color: #ff0000;">&quot;xpointer(/address-book/persons/person[@id='3'])&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;xi</span> :include <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;address-book.xml&quot;</span> <span style="color: #000066;">xpointer</span>=<span style="color: #ff0000;">&quot;xpointer(/address-book/persons/person[@id='4'])&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;/persons<span style="font-weight: bold; color: black;">&gt;</span></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; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/group<span style="font-weight: bold; color: black;">&gt;</span></span></span>&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; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/groups<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;/address<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
<p>Wycieliśmy element groups wraz z jego dziećmi z pliku address-book.xml, dodając przy wartościach dołączanych atrybut href, wskazujący na plik w którym znajduje się nasz XML z osobami.</p>
<h3>XSLT</h3>
<p>Format XML jest dość czytelnym formatem jednak nie nadaje się on do prezentacji. Zdecydowanie lepszym pomysłem jest wyświetlić dane osadzając je ładnie np.: w HTMLu. Mamy do wyboru dwie drogi: pierwsza użycie DOM w PHP, parsując dokument i wyświetlając go wg. naszych oczekiwań. Drugim, lepszym sposobem, jest stworzenie pliku XSL oraz wykonać transformację przy użyciu XSLT.</p>
<p>Pliki XSL są dokumentami opisującymi sposób prezentacji i przekształceń dokumentów XML. Spróbujemy teraz pisząc kilka prostych podstawowych instrukcji, przekształcić XML naszej książki aby była ona prezentowana w formie tabeli HTML.</p>
<p>Jako że nasz plik jest dość prosty to w również prosty sposób zaprezentujemy go w tabeli html, przy okazji sortując</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_4a5f4d70371d1">
<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_4a5f4d70371d1').style.display='block';document.getElementById('plain_synthi_4a5f4d70371d1').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_4a5f4d70371d1">
<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_4a5f4d70371d1').style.display='block';document.getElementById('styled_synthi_4a5f4d70371d1').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;xsl</span> :stylesheet <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> xmlns:<span style="color: #000066;">xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&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;/xsl<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl</span> :template <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&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;html<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;head<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;title<span style="font-weight: bold; color: black;">&gt;</span></span></span>XML - morze możliwości<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/title<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;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;meta</span> <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="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; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;meta</span> <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="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;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/head<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;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;body<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;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;h2<span style="font-weight: bold; color: black;">&gt;</span></span></span>Książka adresowa<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/h2<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;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;table<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;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tr<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;th<span style="font-weight: bold; color: black;">&gt;</span></span></span>Imię<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/th<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;th<span style="font-weight: bold; color: black;">&gt;</span></span></span>Nazwisko<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/th<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;th<span style="font-weight: bold; color: black;">&gt;</span></span></span>E-Mail<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/th<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;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tr<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;xsl</span> :for-each <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;address-book/persons/person&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;xsl</span> :sort <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;lastname&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;tr<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;td<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl</span> :value-of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;firstname&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/td<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;td<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl</span> :value-of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;lastname&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/td<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;td<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl</span> :value-of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;email&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/td<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; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tr<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;/xsl<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;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/table<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;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/body<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;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/html<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;/xsl<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
<p>Plik zaczynami od przypisania prefixu dla przestrzeni nazw XSL. Następie posługujemy się elementem xsl:template który definiuje szablon. Nasz szablon zaczyna się od podstawowych elementów html. Aby przetworzyć każdą osobę posłużymy się elementem xsl:for-each, w atrybucie select zaznaczając zbiór węzów do przetworznia używając wyrażeń XPath. Następnie zaznaczamy że chceby aby osoby były posortowane alfabetycznie wg. nazwiska i umieszczamy szablon który ma być używany przy każdym elemencie który ma być przetworzony. Zawiera on html wiersza tabeli. W komórkach tabeli do wyświetlenia imienia i nazwiska osoby użwywamy elementu xsl:value-of który zwraca wartość węzła podanego w atrybucie select. Trzeba zwrócić uwagę na to że podajemy tam wyrażenie XPath węzła który jest dostarczany przez xsl:for-each. W naszym przypadku będzie to np.:</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_4a5f4d703f973">
<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_4a5f4d703f973').style.display='block';document.getElementById('plain_synthi_4a5f4d703f973').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_4a5f4d703f973">
<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_4a5f4d703f973').style.display='block';document.getElementById('styled_synthi_4a5f4d703f973').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;firstname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Jan<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/firstname<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;lastname<span style="font-weight: bold; color: black;">&gt;</span></span></span>Kowlaski<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastname<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;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>jan-kowalski@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<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;phone<span style="font-weight: bold; color: black;">&gt;</span></span></span>000 123 456<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/phone<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;city<span style="font-weight: bold; color: black;">&gt;</span></span></span>Warszawa<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/city<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
<p>Dlatego też atrybut select będzie zawierał wyrażenie firstname/ a nie jak niektóry mogli mylnie sądzić address-book/persons/person/firstname. Na końcu dodajmy w pliku naszej książki linijkę podpinającą plik XSL:</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_4a5f4d7041621">
<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_4a5f4d7041621').style.display='block';document.getElementById('plain_synthi_4a5f4d7041621').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_4a5f4d7041621">
<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_4a5f4d7041621').style.display='block';document.getElementById('styled_synthi_4a5f4d7041621').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;</span> ?xml-stylesheet <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/xsl&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;address-book.xsl&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;address</span> -book xmlns:<span style="color: #000066;">xi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XInclude&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;persons<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; [...]</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;/persons<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;/address<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
<p>Gdy otworzymy teraz plik XML naszej książki w przeglądarce naszym oczom ukaże się tabelka z osobami a nie drzewo z XML&#8217;em.</p>
<p>W tym przypadku processorem XSLT był silnik przeglądarki. Jednak możemy zrobić to samo używając PHP i DOM&#8217;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_4a5f4d70443cd">
<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_4a5f4d70443cd').style.display='block';document.getElementById('plain_synthi_4a5f4d70443cd').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_4a5f4d70443cd">
<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_4a5f4d70443cd').style.display='block';document.getElementById('styled_synthi_4a5f4d70443cd').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: #0000ff;">$dom</span> = <span style="color: #000000; font-weight: bold;">new</span> DomDocument<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;"><span style="color: #0000ff;">$dom</span>-&gt;<span style="color: #006600;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;address-book.xml&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;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$xsl</span> = <span style="color: #000000; font-weight: bold;">new</span> DomDocument<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;"><span style="color: #0000ff;">$xsl</span>-&gt;<span style="color: #006600;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;address-book.xsl&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;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$xslt</span> = <span style="color: #000000; font-weight: bold;">new</span> XsltProcessor<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;"><span style="color: #0000ff;">$xslt</span>-&gt;<span style="color: #006600;">importStyleSheet</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$xsl</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;"><a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$xslt</span>-&gt;<span style="color: #006600;">transformToXML</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$dom</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: #000000; font-weight: bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
<p>Zaczynamy od stworzenia dwóch obiektów DOM. Pierwszy ładuje plik adress-book.xml czyli naszą książkę, natomiast drugi address-book.xsl zawierający arkusz z przekształceniami. Następnie tworzymy obiekt XsltProcessor który najpierw importuje plik XSL następnie wykonuje transformacje do HTML na naszej książce.</p>
<h3>Podsumowanie</h3>
<p>XML jest potężnym narzędziem. W tym artykule poruszyłem tylko podstawowe zagadnienia oraz możliwości. Odpowiednio XPath, XInclude, XSLT mają dużo obszerne dokumenacje i potrafią zdziałąć dużo więcej. Większość z was może czuć nie dosyt i odnieśc wrażenie artykuł został napisany bardzo powieszchownie. Otóż takie było moje założenie. Chciałem pokazać jakie możwliości posiada XML i wszystkie jego standarty oraz zachęcić was do ich używania, teraz kiedy już widzać z czym się to je, oraz że może okazać się to bardzo przyadtne i pomoce. Każdy z poruszonych tutaj standartów &#8220;potrafi&#8221; zdecydowanie więcej. Wyrażenia XPath mogą bardzo szczegółowo selekcjonować wartości które potrzebujemy. Natomiast XSLT posiada szereg kilku innych elementów służących do transformacji. W notce pokazałem jak przetworzyć XML do HTML&#8217;a. Jednak XSLT bardzo często jest używany również do transformacji pliku XML w inny.</p>
<h4>Dodatkowe materiały</h4>
<ul>
<li><a href="http://www.w3schools.com/xml/default.asp">W3Schools.com</a> - serwis z artykułami o XML i nie tylko. Dużo przykładów, można bardzo szybko się wielu rzeczy nauczyć</li>
<li><a href="http://students.mimuw.edu.pl/SR/prace-mgr/bienkowski/Praca.htm">Implementacja standardów XPointer i XInclude</a>, praca magisterska Karola Bieńkowskiego. Ten Pan w przeciwieństwie do mnie opracował wszystko bardzo szczegółowo</li>
<li><a href="http://www.amazon.com/Pro-PHP-XML-Web-Services/dp/1590596331/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1227815773&#038;sr=8-1">Pro PHP XML and Web Services</a>, książka wydawnictwa Apress. Dokładnie opisany cały XMLowy świat oraz jego zastosowanie używając PHP.</li>
</ul>
<p><em>Artykuł zajął <a href="http://wortal.php.pl/wortal/aktualnosci/wydarzenia/konkursy/doceniamy_publicystow_wyniki">drugie miejsce</a> w konkursie <a href="http://wortal.php.pl/wortal/aktualnosci/wydarzenia/konkursy/konkurs_doceniamy_publicystow">Doceniamy Publicystów</a> zorganizowanym przez wortal php.pl</em></p>
]]></content:encoded>
			<wfw:commentRss>http://strzalek.net/blog/7/xml-morze-mozliwosci-xpath-xpointer-xinclude/feed</wfw:commentRss>
		<feedburner:origLink>http://strzalek.net/blog/7/xml-morze-mozliwosci-xpath-xpointer-xinclude</feedburner:origLink></item>
		<item>
		<title>Agavi - Wprowadzenie</title>
		<link>http://feedproxy.google.com/~r/strzalek-devblog/~3/3e4mfQTewyA/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_4a5f4d71a9a67">
<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_4a5f4d71a9a67').style.display='block';document.getElementById('plain_synthi_4a5f4d71a9a67').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_4a5f4d71a9a67">
<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_4a5f4d71a9a67').style.display='block';document.getElementById('styled_synthi_4a5f4d71a9a67').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_4a5f4d71a9ccb">
<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_4a5f4d71a9ccb').style.display='block';document.getElementById('plain_synthi_4a5f4d71a9ccb').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_4a5f4d71a9ccb">
<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_4a5f4d71a9ccb').style.display='block';document.getElementById('styled_synthi_4a5f4d71a9ccb').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_4a5f4d71a9f07">
<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_4a5f4d71a9f07').style.display='block';document.getElementById('plain_synthi_4a5f4d71a9f07').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_4a5f4d71a9f07">
<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_4a5f4d71a9f07').style.display='block';document.getElementById('styled_synthi_4a5f4d71a9f07').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_4a5f4d71aa105">
<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_4a5f4d71aa105').style.display='block';document.getElementById('plain_synthi_4a5f4d71aa105').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_4a5f4d71aa105">
<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_4a5f4d71aa105').style.display='block';document.getElementById('styled_synthi_4a5f4d71aa105').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_4a5f4d71aa589">
<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_4a5f4d71aa589').style.display='block';document.getElementById('plain_synthi_4a5f4d71aa589').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_4a5f4d71aa589">
<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_4a5f4d71aa589').style.display='block';document.getElementById('styled_synthi_4a5f4d71aa589').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_4a5f4d71abea9">
<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_4a5f4d71abea9').style.display='block';document.getElementById('plain_synthi_4a5f4d71abea9').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_4a5f4d71abea9">
<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_4a5f4d71abea9').style.display='block';document.getElementById('styled_synthi_4a5f4d71abea9').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_4a5f4d71acc64">
<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_4a5f4d71acc64').style.display='block';document.getElementById('plain_synthi_4a5f4d71acc64').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_4a5f4d71acc64">
<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_4a5f4d71acc64').style.display='block';document.getElementById('styled_synthi_4a5f4d71acc64').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_4a5f4d71b1c2a">
<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_4a5f4d71b1c2a').style.display='block';document.getElementById('plain_synthi_4a5f4d71b1c2a').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_4a5f4d71b1c2a">
<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_4a5f4d71b1c2a').style.display='block';document.getElementById('styled_synthi_4a5f4d71b1c2a').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_4a5f4d71b665c">
<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_4a5f4d71b665c').style.display='block';document.getElementById('plain_synthi_4a5f4d71b665c').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_4a5f4d71b665c">
<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_4a5f4d71b665c').style.display='block';document.getElementById('styled_synthi_4a5f4d71b665c').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_4a5f4d71b8611">
<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_4a5f4d71b8611').style.display='block';document.getElementById('plain_synthi_4a5f4d71b8611').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_4a5f4d71b8611">
<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_4a5f4d71b8611').style.display='block';document.getElementById('styled_synthi_4a5f4d71b8611').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_4a5f4d71c8eaf">
<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_4a5f4d71c8eaf').style.display='block';document.getElementById('plain_synthi_4a5f4d71c8eaf').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_4a5f4d71c8eaf">
<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_4a5f4d71c8eaf').style.display='block';document.getElementById('styled_synthi_4a5f4d71c8eaf').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_4a5f4d71d13ef">
<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_4a5f4d71d13ef').style.display='block';document.getElementById('plain_synthi_4a5f4d71d13ef').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_4a5f4d71d13ef">
<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_4a5f4d71d13ef').style.display='block';document.getElementById('styled_synthi_4a5f4d71d13ef').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_4a5f4d71d7780">
<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_4a5f4d71d7780').style.display='block';document.getElementById('plain_synthi_4a5f4d71d7780').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_4a5f4d71d7780">
<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_4a5f4d71d7780').style.display='block';document.getElementById('styled_synthi_4a5f4d71d7780').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_4a5f4d71de9ed">
<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_4a5f4d71de9ed').style.display='block';document.getElementById('plain_synthi_4a5f4d71de9ed').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_4a5f4d71de9ed">
<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_4a5f4d71de9ed').style.display='block';document.getElementById('styled_synthi_4a5f4d71de9ed').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_4a5f4d71ea739">
<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_4a5f4d71ea739').style.display='block';document.getElementById('plain_synthi_4a5f4d71ea739').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_4a5f4d71ea739">
<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_4a5f4d71ea739').style.display='block';document.getElementById('styled_synthi_4a5f4d71ea739').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_4a5f4d7203ebf">
<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_4a5f4d7203ebf').style.display='block';document.getElementById('plain_synthi_4a5f4d7203ebf').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_4a5f4d7203ebf">
<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_4a5f4d7203ebf').style.display='block';document.getElementById('styled_synthi_4a5f4d7203ebf').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_4a5f4d72110d7">
<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_4a5f4d72110d7').style.display='block';document.getElementById('plain_synthi_4a5f4d72110d7').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_4a5f4d72110d7">
<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_4a5f4d72110d7').style.display='block';document.getElementById('styled_synthi_4a5f4d72110d7').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_4a5f4d721e3b5">
<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_4a5f4d721e3b5').style.display='block';document.getElementById('plain_synthi_4a5f4d721e3b5').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_4a5f4d721e3b5">
<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_4a5f4d721e3b5').style.display='block';document.getElementById('styled_synthi_4a5f4d721e3b5').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://feedproxy.google.com/~r/strzalek-devblog/~3/TzSeyXV1Olk/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_4a5f4d73522bf">
<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_4a5f4d73522bf').style.display='block';document.getElementById('plain_synthi_4a5f4d73522bf').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_4a5f4d73522bf">
<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_4a5f4d73522bf').style.display='block';document.getElementById('styled_synthi_4a5f4d73522bf').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_4a5f4d735ca99">
<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_4a5f4d735ca99').style.display='block';document.getElementById('plain_synthi_4a5f4d735ca99').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_4a5f4d735ca99">
<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_4a5f4d735ca99').style.display='block';document.getElementById('styled_synthi_4a5f4d735ca99').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_4a5f4d736777a">
<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_4a5f4d736777a').style.display='block';document.getElementById('plain_synthi_4a5f4d736777a').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_4a5f4d736777a">
<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_4a5f4d736777a').style.display='block';document.getElementById('styled_synthi_4a5f4d736777a').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_4a5f4d737b867">
<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_4a5f4d737b867').style.display='block';document.getElementById('plain_synthi_4a5f4d737b867').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_4a5f4d737b867">
<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_4a5f4d737b867').style.display='block';document.getElementById('styled_synthi_4a5f4d737b867').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_4a5f4d738b27a">
<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_4a5f4d738b27a').style.display='block';document.getElementById('plain_synthi_4a5f4d738b27a').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_4a5f4d738b27a">
<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_4a5f4d738b27a').style.display='block';document.getElementById('styled_synthi_4a5f4d738b27a').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: #006600;">Category</span> -&gt; <span style="color: #006600;">name</span> = <span style="color: #ff0000;">&quot;Programowanie&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;">save</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;</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>Tworzymy nowy obiekt rekordu Product. Następnie ustawiamy po kolei wartości. W deklaracji rekordu zaznaczyliśmy że zachodzą relacje one-to-one z rekordami Category i Company. Dostęp do obiektów tych rekordów mamy poprzez właściwości o nazwie relacji. Mogli byśmy podać $product -> Company -> id = 1; ale na razie nie mamy żadnej kategorii ani firmy więc dodając produkt dodajemy nową kategorię oraz firmę.</p>
<h4>Pobieranie</h4>
<p>Jest kilka sposobów aby wyciągać rekordy z bazy danych. Najszybszym jest użycie magicznych metod find, udostępnianych przez Doctrine_Table:</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_4a5f4d739954f">
<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_4a5f4d739954f').style.display='block';document.getElementById('plain_synthi_4a5f4d739954f').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_4a5f4d739954f">
<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_4a5f4d739954f').style.display='block';document.getElementById('styled_synthi_4a5f4d739954f').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;<span style="color: #0000ff;">$table</span> = Doctrine::<span style="color: #006600;">getTable</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Product&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;</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: #0000ff;">$table</span> -&gt; <span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</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> = <span style="color: #0000ff;">$table</span> -&gt; <span style="color: #006600;">findOneByPrice</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1500</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;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Produkt: &quot;</span>.<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">name</span>.<span style="color: #ff0000;">&quot;&lt;br /&gt;&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Kategoria: &quot;</span>.<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">Category</span> -&gt; <span style="color: #006600;">name</span>.<span style="color: #ff0000;">&quot;&lt;br /&gt;&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Producent: &quot;</span>.<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">Company</span> -&gt; <span style="color: #006600;">name</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;">$products</span> = <span style="color: #0000ff;">$table</span> -&gt; <span style="color: #006600;">findByCompany</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</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;">$products</span> = <span style="color: #0000ff;">$table</span> -&gt; <span style="color: #006600;">findAll</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;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;&lt;ul&gt;&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$products</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$product</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: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;&lt;li&gt;&quot;</span>.<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">name</span>.<span style="color: #ff0000;">&quot;&lt;/li&gt;&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&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;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;&lt;/ul&gt;&quot;</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>
<p>Pierwsze dwie metody zwracają nam obiekt Product. Następnie wyświetlamy nazwę: produktu, kategorii oraz firmy. I tutaj trzeba zwrócić uwagę na bardzo ważną rzecz. Otóż stosując lazy-loading wywoływane są 3 zapytania, a nie jedno z JOINEM. A o tym jak pobrać w jednym zapytaniu to wszystko za chwilę (DQL).</p>
<p>Następnie znajdujemy wszystkie produktu, lub te gdzie company = 1. Zmienna products jest obiektem Doctrine_Collection, posiadającym pobrane rekordu. Jako że Doctrine_Collection implementuje interface ArrayAccess, oraz Iterator, możemy używać $products jako tablica.</p>
<h4>Zmiana</h4>
<p>Aby zmienić rekord używając obiektu rekordu, najpierw musimy pobrać rekord z bazy danych. Najprostszym sposobem jest użycie metody find która szuka po kluczu głównym (id)</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_4a5f4d73aabcb">
<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_4a5f4d73aabcb').style.display='block';document.getElementById('plain_synthi_4a5f4d73aabcb').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_4a5f4d73aabcb">
<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_4a5f4d73aabcb').style.display='block';document.getElementById('styled_synthi_4a5f4d73aabcb').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;<span style="color: #0000ff;">$product</span> = Doctrine::<span style="color: #006600;">getTable</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Product&quot;</span><span style="color: #66cc66;">&#41;</span> -&gt; <span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</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;<a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">toArray</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;</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 v.5 Professional Edition&quot;</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;">//Update zmienionych wartości czyli tylko &quot;name&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;">save</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;<a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">toArray</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;"><span style="color: #000000; font-weight: bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
<h4>Usunięcie</h4>
<p>Aby usunąć jakiś obiekt z bazy danych wystarczy użyć metody delete().</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_4a5f4d73b0928">
<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_4a5f4d73b0928').style.display='block';document.getElementById('plain_synthi_4a5f4d73b0928').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_4a5f4d73b0928">
<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_4a5f4d73b0928').style.display='block';document.getElementById('styled_synthi_4a5f4d73b0928').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;">&nbsp;<span style="color: #0000ff;">$product</span> = Doctrine::<span style="color: #006600;">getTable</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Product&quot;</span><span style="color: #66cc66;">&#41;</span> -&gt; <span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</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: #808080; font-style: italic;">//Produkt został usunięty z bazy danych.</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;">delete</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;</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>DQL - Doctrine Query Language</h3>
<p>Magiczne DQL nie jest żadnym nowym językiem służącym do komunikacji z bazą danych - właściwie jest to trochę uproszczony SQL. Zapytania DQL pisze się za pomocą fluent interface, używając obiektu Doctrine_Query. Oto jak wygląda zapytanie które zwróci nam produkt wraz z jego kategorią oraz firmą:</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_4a5f4d73b5023">
<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_4a5f4d73b5023').style.display='block';document.getElementById('plain_synthi_4a5f4d73b5023').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_4a5f4d73b5023">
<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_4a5f4d73b5023').style.display='block';document.getElementById('styled_synthi_4a5f4d73b5023').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;<span style="color: #0000ff;">$product</span> = Doctrine_Query::<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> -&gt; <span style="color: #006600;">from</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Product p&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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; <span style="color: #006600;">leftJoin</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;p.Category cat&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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; <span style="color: #006600;">leftJoin</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;p.Company c&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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; <span style="color: #006600;">where</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;p.id = ?&quot;</span>, <span style="color: #cc66cc;">6</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; <span style="color: #006600;">fetchOne</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;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Produkt: &quot;</span>.<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">name</span>.<span style="color: #ff0000;">&quot;&lt;br /&gt;&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Kategoria: &quot;</span>.<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">Category</span> -&gt; <span style="color: #006600;">name</span>.<span style="color: #ff0000;">&quot;&lt;br /&gt;&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Producent: &quot;</span>.<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">Company</span> -&gt; <span style="color: #006600;">name</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;<a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">toArray</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;"><span style="color: #000000; font-weight: bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
<p>Zasadniczą różnicą między DQL a SQL jest to że nie podajemy nazw tabel lecz nazwy rekordów. Dodatkowo przy JOINach nie musimy pisać ON col1 = col2 ponieważ Doctrine zna zarówno nazwę tabeli jak i nazwy kolumn między którymi zachodzi relacja. Na końcu wywołujemy fetchOne, chcąc dostać obiekt Product a nie obiekt Doctrine_Collection z jednym produktem :) Tak natomiast będzie wyglądać wyciągnięcie firmy oraz jej produktów:</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_4a5f4d73c4298">
<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_4a5f4d73c4298').style.display='block';document.getElementById('plain_synthi_4a5f4d73c4298').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_4a5f4d73c4298">
<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_4a5f4d73c4298').style.display='block';document.getElementById('styled_synthi_4a5f4d73c4298').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;<span style="color: #0000ff;">$company</span> = Doctrine_Query::<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> -&gt; <span style="color: #006600;">from</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Company c&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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; <span style="color: #006600;">leftJoin</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;c.Products p&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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; <span style="color: #006600;">where</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;c.id = ?&quot;</span>, <span style="color: #cc66cc;">1</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; <span style="color: #006600;">fetchOne</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;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Firma: &quot;</span>.<span style="color: #0000ff;">$company</span> -&gt; <span style="color: #006600;">name</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;&lt;ul&gt;&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$company</span> -&gt; <span style="color: #006600;">Products</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$product</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: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;&lt;li&gt;&quot;</span>.<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">name</span>.<span style="color: #ff0000;">&quot;&lt;/li&gt;&quot;</span>;&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&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;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;&lt;/ul&gt;&quot;</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>
<p>oraz wyciągnięcie wszystkich produktów z kategorii programowanie:</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_4a5f4d73d226f">
<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_4a5f4d73d226f').style.display='block';document.getElementById('plain_synthi_4a5f4d73d226f').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_4a5f4d73d226f">
<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_4a5f4d73d226f').style.display='block';document.getElementById('styled_synthi_4a5f4d73d226f').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;<span style="color: #0000ff;">$products</span> = Doctrine_Query::<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> -&gt; <span style="color: #006600;">from</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Product p&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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt; <span style="color: #006600;">leftJoin</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;p.Category cat&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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt; <span style="color: #006600;">where</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cat.name = ?&quot;</span>, <span style="color: #ff0000;">&quot;Programowanie&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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&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;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Produkty należace do kategori Programowanie&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;&lt;ul&gt;&quot;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &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;<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$products</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$product</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: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;&lt;li&gt;&quot;</span>.<span style="color: #0000ff;">$product</span> -&gt; <span style="color: #006600;">name</span>.<span style="color: #ff0000;">&quot;&lt;/li&gt;&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&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;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;&lt;/ul&gt;&quot;</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>Zaawansowane możliwości</h3>
<p>Zaprezentowane wyżej możliwości to podstawowe funkcjonalności które oferuje nam ten ORM. Doctrine jest zaawansowanym narzędziem z którego można &#8220;wycisnąć&#8221; dużo więcej niż proste operacje CRUD oraz zapytania do bazy. O zaawansowanych możliwościach takich jak Event Listeners, Templates, Plugins, Cache oraz Migrations w następnej notce.</p>
<p>Jeżeli zachęciłem was do Doctrine to zapraszam do <a href="http://www.phpdoctrine.org/documentation">dokumentacji</a>. Polecam ją przeczytaj od początku do końca aby dowiedzieć się jak ogromne możliwości oferuje nam to narzędzie. Jeżeli pojawią się jakieś problemy a dokumentacja nie wystarczy, pomoc zawsze znajdziecie na kanale <a href="irc://irc.freenode.net/doctrine">#doctrine na serwerze freenode.net</a></p>
<p>Wszystkie listningi można <a href="./sources/doctrine_tests.zip">ściągnąć</a> i uruchomić na swoim komputerze.</p>
]]></content:encoded>
			<wfw:commentRss>http://strzalek.net/blog/4/doctrine-orm-dla-php/feed</wfw:commentRss>
		<feedburner:origLink>http://strzalek.net/blog/4/doctrine-orm-dla-php</feedburner:origLink></item>
		<item>
		<title>Przyjazne URLe - piszemy router</title>
		<link>http://feedproxy.google.com/~r/strzalek-devblog/~3/2Jso5d-gwTQ/przyjazne-urle-piszemy-router</link>
		<comments>http://strzalek.net/blog/3/przyjazne-urle-piszemy-router#comments</comments>
		<pubDate>Fri, 26 Oct 2007 17:34:54 +0000</pubDate>
		<dc:creator>Strzałek</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[router]]></category>

		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://strzalek.net/blog/3/przyjazne-urle-piszemy-router</guid>
		<description><![CDATA[Czym są przyjazne urle? Są to adresy w formacie http://strona.pl/nowosci/php/nowa-wersja-php-wydana, a nie tak standardowe i niewygodne adresy ze zmienny GET: http://strona.pl/index.php?module=news&#038;category=php&#038;title=nowa-wersja-php-wydana. Pierwszą rzeczą która skłania programistów do korzystania z przyjaznych urli jest to że są one rzeczywiście przyjazne. Można bardzo prosto zapamiętać taki link, znacznie łatwiej niż standardowy link ze zmiennymi GET. Wygodnie możemy na [...]]]></description>
			<content:encoded><![CDATA[<p>Czym są przyjazne urle? Są to adresy w formacie http://strona.pl/nowosci/php/nowa-wersja-php-wydana, a nie tak standardowe i niewygodne adresy ze zmienny GET: http://strona.pl/index.php?module=news&#038;category=php&#038;title=nowa-wersja-php-wydana. Pierwszą rzeczą która skłania programistów do korzystania z przyjaznych urli jest to że są one rzeczywiście przyjazne. Można bardzo prosto zapamiętać taki link, znacznie łatwiej niż standardowy link ze zmiennymi GET. Wygodnie możemy na przykład umieszczać reklamy w gazetach - http://sklep.pl/konkurs. Drugą sprawą jest to iż przyjazne urle są łatwe do indeksowania dla wyszukiwarek. Roboty indeksujące strony wyżej zindeksują nasz pierwszy przykładowy link niż ten drugi, przestarzały rupieć ;)<br />
<span id="more-3"></span></p>
<h3>Podstawy</h3>
<p>Ok, po wstępnie zapewne czytelniku jesteś żądny wiedzy. Jak uzyskać takie urle? Bardzo prosto. Cała magia zawiera się w PATH INFO.<br />
2 krótkie linijki:</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_4a5f4d747dd20">
<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_4a5f4d747dd20').style.display='block';document.getElementById('plain_synthi_4a5f4d747dd20').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_4a5f4d747dd20">
<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_4a5f4d747dd20').style.display='block';document.getElementById('styled_synthi_4a5f4d747dd20').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;"><span style="color: #0000ff;">$pathInfoParams</span> = <a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span>’/<span style="color: #ff0000;">&#8216;, substr($_SERVER[’PATH_INFO’], 1));</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">var_dump($pathInfoParams);</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">?&gt; </span></div>
</li>
</ol>
</div>
</div>
<p>Prosty skrypt który po odpaleniu, pokaże nam dump&#8217;a tablicy, którą utworzyliśmy rozbijając dane z patch info ;) Wiedząc skąd brać nasze wejście trzeba by to teraz jakoś obsłużyć.<br />
Router – wygodny interfejs</p>
<p>Skoro wszystko trzymane jest w PATH INFO, wiemy również jak to przetworzyć i użyć. Jednak takie rozwiązanie nas w ogóle nie zadowala. Strukturalny kod, który nie wygodnie wdrożyć w systemie. Przydało by się napisać ładną klasę odpowiedzialną za wszystko związane z adresem. I tutaj pojawia się nazwa Router. Cóż to za cudo? Router w aplikacjach internetowych służy do analizowania URLi, oraz ich generowania.</p>
<p>Przedstawię teraz przykładową implementację Routera:</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_4a5f4d7480e09">
<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_4a5f4d7480e09').style.display='block';document.getElementById('plain_synthi_4a5f4d7480e09').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_4a5f4d7480e09">
<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_4a5f4d7480e09').style.display='block';document.getElementById('styled_synthi_4a5f4d7480e09').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;<span style="color: #000000; font-weight: bold;">class</span> NiceUrlsRouter <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;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;protected <span style="color: #0000ff;">$input</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; &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: #0000ff;">$controller</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; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #0000ff;">$action</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; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #0000ff;">$params</span> = <span style="color: #000000; font-weight: bold;">null</span>;&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;const URL_DELIMITER = <span style="color: #ff0000;">&#8216;/&#8217;</span>; </div>
</li>
</ol>
</div>
</div>
<p>Zadeklarowaliśmy 4 właściwości przechowywujące odpowiednio, wejście, kontroler, akcję oraz tablicę z parametrami. Na końcu jedna stała która przechowuje separator. Dalej piszemy niezbędne metody:</p>
</pre>
<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_4a5f4d7484867">
<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_4a5f4d7484867').style.display='block';document.getElementById('plain_synthi_4a5f4d7484867').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_4a5f4d7484867">
<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_4a5f4d7484867').style.display='block';document.getElementById('styled_synthi_4a5f4d7484867').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;"><span style="color: #808080; font-style: italic;">/**</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;">&nbsp; &nbsp; * Ustawienie inputu który później</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;">&nbsp; &nbsp; * zostaje parsowany</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;">&nbsp; &nbsp; *</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;">&nbsp; &nbsp; * @param string $input</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;">&nbsp; &nbsp; */</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> setInput<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">&#41;</span><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; <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">input</span> = <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">prepare</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$input</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; <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; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * Ustawienie parametrow</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; *</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * @param array $params</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; */</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setParams<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$params</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span> &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: #0000ff;">$this</span> -&gt; <span style="color: #006600;">controller</span> = <a href="http://www.php.net/array_shift"><span style="color: #000066;">array_shift</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$params</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; <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">action</span> = <a href="http://www.php.net/array_shift"><span style="color: #000066;">array_shift</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$params</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; <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">params</span> = <span style="color: #0000ff;">$params</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; <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; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&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; <span style="color: #808080; font-style: italic;">/**</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * Przygotowanie urla do parsowania.</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * Czyszczenie ze zbednych rzeczy.</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; *</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * @param string $input</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * @return string</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; */</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> prepare<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</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; </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; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$input</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">&#8216;/&#8217;</span><span style="color: #66cc66;">&#41;</span><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; &nbsp;<span style="color: #0000ff;">$input</span> = <a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$input</span>, <span style="color: #cc66cc;">1</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; <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; &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: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$input</span>, <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">&#8216;/&#8217;</span><span style="color: #66cc66;">&#41;</span><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;">$input</span> = <a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$input</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">-1</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; <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;&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: #b1b100;">return</span> <span style="color: #0000ff;">$input</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&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; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * Parsowanie inputu</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; *</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * @return bool</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; */</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> parse<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><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; </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;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">input</span><span style="color: #66cc66;">&#41;</span><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;&nbsp; &nbsp;<span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">setParams</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span>self::<span style="color: #006600;">URL_DELIMITER</span>, <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">input</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;&nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</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: #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; &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;<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&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; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * Tworzenie url&#8217;a</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; *</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * @param array $params</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * @return string</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;"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; */</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.php.net/static"><span style="color: #000066;">static</span></a> <span style="color: #000000; font-weight: bold;">function</span> url<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$params</span><span style="color: #66cc66;">&#41;</span><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; </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;">$url</span> = <span style="color: #ff0000;">&#8216;http://&#8217;</span>.<span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&#8216;SERVER_NAME&#8217;</span><span style="color: #66cc66;">&#93;</span>.<a href="http://www.php.net/str_replace"><span style="color: #000066;">str_replace</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;index.php&#8217;</span>, <span style="color: #ff0000;">&#8221;</span>, <span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&#8216;SCRIPT_NAME&#8217;</span><span style="color: #66cc66;">&#93;</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;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/is_array"><span style="color: #000066;">is_array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$params</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><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;&nbsp; <span style="color: #0000ff;">$params</span> = <a href="http://www.php.net/func_get_args"><span style="color: #000066;">func_get_args</span></a><span style="color: #66cc66;">&#40;</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: #66cc66;">&#125;</span>&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; </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;">$params</span> = <a href="http://www.php.net/implode"><span style="color: #000066;">implode</span></a><span style="color: #66cc66;">&#40;</span>self::<span style="color: #006600;">URL_DELIMITER</span>, <span style="color: #0000ff;">$params</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: #0000ff;">$url</span>.<span style="color: #0000ff;">$params</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&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; &nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
<p>Nie mam tutaj nic skomplikowanego. Krótki opis najważnieszych metod:</p>
<ul>
<li><em>bool</em> parse() - parsuje zawratość właściwości $input, pierwsze 2 elementy są umieszczane odpowiednio we właściwościach $contoller i $action, reszta ląduje w $params.</li>
<li><em>string</em> url(<em>array</em> $params) – statyczna metoda tworząca url</li>
</ul>
<p>Wszystko gotowe, przykładowe użycie świeżo napisanej klasy jest bardzo proste.</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_4a5f4d749dff6">
<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_4a5f4d749dff6').style.display='block';document.getElementById('plain_synthi_4a5f4d749dff6').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_4a5f4d749dff6">
<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_4a5f4d749dff6').style.display='block';document.getElementById('styled_synthi_4a5f4d749dff6').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;"><span style="color: #0000ff;">$router</span> = <span style="color: #000000; font-weight: bold;">new</span> NiceUrlsRouter<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;">$router</span> -&gt; <span style="color: #006600;">setInput</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&#8216;PATH_INFO&#8217;</span><span style="color: #66cc66;">&#93;</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: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$router</span> -&gt; <span style="color: #006600;">parse</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><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;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&#8216;Kontroler: &#8216;</span>.<span style="color: #0000ff;">$router</span> -&gt; <span style="color: #006600;">controller</span>.<span style="color: #ff0000;">&#8216;&lt;br /&gt;&#8217;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&#8216;Akcja: &#8216;</span>.<span style="color: #0000ff;">$router</span> -&gt; <span style="color: #006600;">action</span>.<span style="color: #ff0000;">&#8216;&lt;br /&gt;&#8217;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&#8216;Parametry: &#8216;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$router</span> -&gt; <span style="color: #006600;">params</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: #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;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&#8216;Wygenerowany url: &#8216;</span>.NiceUrlsRouter::<span style="color: #006600;">url</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array_merge"><span style="color: #000066;">array_merge</span></a><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: #0000ff;">$router</span> -&gt; <span style="color: #006600;">controller</span>, <span style="color: #0000ff;">$router</span> -&gt; <span style="color: #006600;">action</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$router</span> -&gt; <span style="color: #006600;">params</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&#8216;&lt;br /&gt;&lt;br /&gt;&#8217;</span>; </div>
</li>
</ol>
</div>
</div>
<p>Jeszcze tylko regułki mod_rewrite, odpowiedzialne za &#8220;usówanie&#8221; index.php z adresu:</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_4a5f4d74abdfc">
<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_4a5f4d74abdfc').style.display='block';document.getElementById('plain_synthi_4a5f4d74abdfc').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_4a5f4d74abdfc">
<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_4a5f4d74abdfc').style.display='block';document.getElementById('styled_synthi_4a5f4d74abdfc').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;">RewriteEngine On
</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">RewriteCond %{REQUEST_FILENAME} !-f
</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">RewriteCond %{REQUEST_FILENAME} !-d
</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">RewriteRule (.*) index.php?$1 [L]</div>
</li>
</ol>
</div>
</div>
<p>Po wejściu na http://localhost/news/show-one/65234 powinniśmy zobaczyć wylistowane wartości które zostały dostarczone przez router. Wszystko działa jak powinno.</p>
<p>Jeszcze jedną rzeczą o której trzeba pamiętć jest umieszczenie w head tagu base, podając adres strony. Dzięki temu będziemy mogli użwać ścieżek względnych w adresach naszych obrazków, plików css etc.</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_4a5f4d74ac623">
<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_4a5f4d74ac623').style.display='block';document.getElementById('plain_synthi_4a5f4d74ac623').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_4a5f4d74ac623">
<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_4a5f4d74ac623').style.display='block';document.getElementById('styled_synthi_4a5f4d74ac623').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/base.html"><span style="color: #000000; font-weight: bold;">&lt;base</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://localhost/&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></a></span> </div>
</li>
</ol>
</div>
</div>
<h3>RewriteRouter</h3>
<p>Z czasem może się okazać że taka prosta funkcjonalność nam nie wystarczy i będziemy chcieli posiadać różne rodzaje URL. Przykładowo:</p>
<ul>
<li>http://strona.pl/news/534.html</li>
<li>http://strona.pl/artykuly/programowanie/php/przyjazne-urle-piszemy-router.html</li>
<li>http://strona.pl/forum/temat/5851.html</li>
</ul>
<p>Zaczynają się schody, ponieważ w takim zapisie nie ma jakiejś ogólnej zasady. Każdy zbudowany jest inaczej i nie wiemy czy pierwsza pozycja to akacja, czy może parametr. A może być tak że w ogóle nie znajdziemy informacji w URL o kontrolerze bądź akcji, a są to przecież niezbędne informacje by nasz front kontroler mógł uruchamiać system. Dodatkowo na końcu dodaliśmy &#8220;.html&#8221; symulujące rozszerzenie, statycznej strony html, co ułatwia indeksowanie, ale całkowicie komplikuje naszą sytuację. Można to rozwiązać udoskonalając nasz router o wcześniej deklarowane drogi z wyrażeniami regularnymi, oraz drogami  którymi mają zostać zastąpione.  Zrobimy sobie dokładnie to samo co robi mod_rewrite w Apache :)</p>
<p>Można sobie pomyśleć że to nie jest łatwa rzecz - nic bardziej mylnego! Prostota implementacji zaskoczyła nawet mnie w momencie gdy programowałem i okazało się że rozwiązanie jest aż tak łatwe.</p>
<p>Zasada działania jest bardzo prosta. Otrzymujemy na wejściu /news/534. A chcemy uruchomić moduł News i akcję ShowOne czyli url powinien wyglądać następująco: /news/showone/534. Potrzebujemy więc przepisać pierwszy URL na drugi i po problemie.</p>
<p>RewriteRouter jest klasą dziedziczącą po NiceUrlsRouter który napisaliśmy przed chwilą. Dodajemy właściwość przetrzymującą reguły, metody do zarządzania regułami, oraz nadpisujemy metodę parse która porównuje URL wejściowy i jeżeli zgadza się on to podmienia go. Oto cała klasa:</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_4a5f4d74aec8e">
<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_4a5f4d74aec8e').style.display='block';document.getElementById('plain_synthi_4a5f4d74aec8e').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_4a5f4d74aec8e">
<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_4a5f4d74aec8e').style.display='block';document.getElementById('styled_synthi_4a5f4d74aec8e').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;"><span style="color: #000000; font-weight: bold;">class</span> RewriteRouter <span style="color: #000000; font-weight: bold;">extends</span> NiceUrlsRouter <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; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #0000ff;">$rules</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>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</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;">&nbsp; &nbsp; &nbsp; &nbsp;* Dodanie reguły</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;">&nbsp; &nbsp; &nbsp; &nbsp;*</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;">&nbsp; &nbsp; &nbsp; &nbsp;* @param string $name</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;">&nbsp; &nbsp; &nbsp; &nbsp;* @param string $pattern</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;">&nbsp; &nbsp; &nbsp; &nbsp;* @param string $url</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;">&nbsp; &nbsp; &nbsp; &nbsp;*/</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: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addRule<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span>, <span style="color: #0000ff;">$pattern</span>, <span style="color: #0000ff;">$url</span><span style="color: #66cc66;">&#41;</span><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;">rules</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#93;</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;pattern&#8217;</span> =&gt; <span style="color: #0000ff;">$pattern</span>, <span style="color: #ff0000;">&#8216;url&#8217;</span> =&gt; <span style="color: #0000ff;">$url</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; <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;</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: #808080; font-style: italic;">/**</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;">&nbsp; &nbsp; &nbsp; &nbsp; * Ustawienie tablicy z regułami</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;">&nbsp; &nbsp; &nbsp; &nbsp; *</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;">&nbsp; &nbsp; &nbsp; &nbsp; * @param array $rules</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;">&nbsp; &nbsp; &nbsp; &nbsp; */</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: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setRules<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rules</span><span style="color: #66cc66;">&#41;</span><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;<span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">rules</span> = <span style="color: #0000ff;">$rules</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; </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: #808080; font-style: italic;">/**</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;">&nbsp; &nbsp; &nbsp; &nbsp; * Sprawdzanie wzoru z regułki.</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;">&nbsp; &nbsp; &nbsp; &nbsp; * Jeżeli się zgadza podmiana urla i</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;">&nbsp; &nbsp; &nbsp; &nbsp; * wykonanie NiceUrlsRouter::parse();</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;">&nbsp; &nbsp; &nbsp; &nbsp; *</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;">&nbsp; &nbsp; &nbsp; &nbsp; * @return bool</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;">&nbsp; &nbsp; &nbsp; &nbsp; */</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> parse<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><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; </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: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">rules</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$name</span> =&gt; <span style="color: #0000ff;">$rule</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</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;<span style="color: #0000ff;">$pattern</span> = <span style="color: #ff0000;">&quot;#^&quot;</span>.<span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">prepare</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rule</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&#8216;pattern&#8217;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot;$#&quot;</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;<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #000066;">preg_match</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$pattern</span>, <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">input</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><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; &nbsp;<span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">setInput</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/preg_replace"><span style="color: #000066;">preg_replace</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$pattern</span>, <span style="color: #0000ff;">$rule</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&#8216;url&#8217;</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #0000ff;">$this</span> -&gt; <span style="color: #006600;">input</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; &nbsp;<span style="color: #b1b100;">return</span> parent::<span style="color: #006600;">parse</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; &nbsp;<span style="color: #b1b100;">break</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;<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; &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; &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: #b1b100;">return</span> parent::<span style="color: #006600;">parse</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; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
<p>Używanie tego routera różni się jedynie tym że przed parsowaniem powinniśmy zadeklarować regułki:</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_4a5f4d74c08f6">
<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_4a5f4d74c08f6').style.display='block';document.getElementById('plain_synthi_4a5f4d74c08f6').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_4a5f4d74c08f6">
<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_4a5f4d74c08f6').style.display='block';document.getElementById('styled_synthi_4a5f4d74c08f6').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;"><span style="color: #0000ff;">$rewriteRouter</span> = <span style="color: #000000; font-weight: bold;">new</span> RewriteRouter<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;">$rewriteRouter</span> -&gt; <span style="color: #006600;">setInput</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&#8216;PATH_INFO&#8217;</span><span style="color: #66cc66;">&#93;</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;">$rewriteRouter</span> -&gt; <span style="color: #006600;">addRule</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;news&#8217;</span>, <span style="color: #ff0000;">&#8216;/news/(<span style="color: #000099; font-weight: bold;">\d</span>+)&#8217;</span>, <span style="color: #ff0000;">&#8216;/news/showOne/$1&#8242;</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;">$rewriteRouter</span> -&gt; <span style="color: #006600;">addRule</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;pages&#8217;</span>, <span style="color: #ff0000;">&#8216;/strona/([a-z1-9<span style="color: #000099; font-weight: bold;">\-</span><span style="color: #000099; font-weight: bold;">\/</span>]+)&#8217;</span>, <span style="color: #ff0000;">&#8216;/pages/showByPath/$1&#8242;</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: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rewriteRouter</span> -&gt; <span style="color: #006600;">parse</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><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;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&#8216;Kontroler: &#8216;</span>.<span style="color: #0000ff;">$rewriteRouter</span> -&gt; <span style="color: #006600;">controller</span>.<span style="color: #ff0000;">&#8216;&lt;br /&gt;&#8217;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&#8216;Akcja: &#8216;</span>.<span style="color: #0000ff;">$rewriteRouter</span> -&gt; <span style="color: #006600;">action</span>.<span style="color: #ff0000;">&#8216;&lt;br /&gt;&#8217;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&#8216;Parametry: &#8216;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rewriteRouter</span> -&gt; <span style="color: #006600;">params</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: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
<p>Nasz router przy parsowaniu wykonuje teraz jedną czynność więcej. Sprawdza czy input zgadza się z wyrażeniem regularnym zawartym w regule. Jeżeli tak, to podmienia do z url zadeklarowanym do podmiany i ten url daje do parsowania metodzie rodzica - NiceUrlsRouter::parse().</p>
<ul>
<li><a href="http://strzalek.net/blog/sources/router.zip">Źródła listningów zamieszczonych w artykule</a></li>
</ul>
<h3>Podsumowanie</h3>
<p>Stworzone w artykule routery są bardzo proste. Służą one raczej jako przykładowa implementacja. Można do nich dodać bardzo dużo innych funkcjonalności. Jako przykład może posłużyć świetny router <a href="http://agavi.org/">frameworka Agavi</a>. W porównaniu do naszych 2 routerów routing w Agavi jest o wiele bardziej złożony i posiada większe możliwości. Całość składa się z <a href="http://trac.agavi.org/browser/branches/0.11/src/routing">kilkunastu plików</a>, a drogi definiuje się w oddzielnym <a href="http://trac.agavi.org/browser/branches/0.11/samples/app/config/routing.xml">pliku xml</a>. Można tam zagnieżdżać drogi, ustawić callback, opcje odpowiedzialne za i18n ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://strzalek.net/blog/3/przyjazne-urle-piszemy-router/feed</wfw:commentRss>
		<feedburner:origLink>http://strzalek.net/blog/3/przyjazne-urle-piszemy-router</feedburner:origLink></item>
		<item>
		<title>Hello world!</title>
		<link>http://feedproxy.google.com/~r/strzalek-devblog/~3/rl0gzDIJJ4s/hello-world</link>
		<comments>http://strzalek.net/blog/1/hello-world#comments</comments>
		<pubDate>Sat, 01 Sep 2007 12:15:06 +0000</pubDate>
		<dc:creator>Strzałek</dc:creator>
		
		<category><![CDATA[offtopic]]></category>

		<guid isPermaLink="false" />
		<description><![CDATA[Witam po dłuższej przerwie. Nie było mnie przez jakiś czas. Spowodowane było to przesiadką na &#8230; prosiaka ;) Mowa o naszym serwerze, z którym było trochę zabawy, co odbiło się na moim blogu - straciłem wszystkie dane. Nie zrobiłem backupu na czas i po notkach zostały wspomnienia. Mam zapisane jedynie 3 najciekawsze które na dniach [...]]]></description>
			<content:encoded><![CDATA[<p>Witam po dłuższej przerwie. Nie było mnie przez jakiś czas. Spowodowane było to przesiadką na &#8230; <a href="http://prosiaczek.org">prosiaka</a> ;) Mowa o naszym serwerze, z którym było trochę zabawy, co odbiło się na moim blogu - straciłem wszystkie dane. Nie zrobiłem backupu na czas i po notkach zostały wspomnienia. Mam zapisane jedynie 3 najciekawsze które na dniach przeredaguję, wzbogacę i ponownie opublikuję.</p>
<p>Pięknie dziękuję <a href="http://blog.chwedziak.pl/">tiraeth&#8217;owi</a> za nowe logo.</p>
]]></content:encoded>
			<wfw:commentRss>http://strzalek.net/blog/1/hello-world/feed</wfw:commentRss>
		<feedburner:origLink>http://strzalek.net/blog/1/hello-world</feedburner:origLink></item>
	</channel>
</rss>
