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

<channel>
	<title>CodeBlog.ch &#187; PHP</title>
	<atom:link href="http://www.codeblog.ch/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codeblog.ch</link>
	<description>Coding and more - Concrete5, Flex, JavaScript</description>
	<lastBuildDate>Mon, 05 Dec 2011 16:10:29 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Angepasste 404 Seite mit Concrete5</title>
		<link>http://www.codeblog.ch/de/2010/01/concrete5-custom-404-page/</link>
		<comments>http://www.codeblog.ch/de/2010/01/concrete5-custom-404-page/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 11:32:55 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=425</guid>
		<description><![CDATA[Es sollte nicht oft vorkommen, aber manchmal landen Internetseiten Besucher auf einer nicht vorhandenen Seite. Oft wird dann eine simple Seite angezeigt mit dem Hinweis dass die Seite nicht verfügbar ist. Etwas mehr Informationen können da hilfreich sein. Besonders wenn eine Seite einem kompletten Redesign unterzogen wurde, kommt es vor, dass Google Besucher auf nicht [...]]]></description>
			<content:encoded><![CDATA[<p>Es sollte nicht oft vorkommen, aber manchmal landen Internetseiten Besucher auf einer nicht vorhandenen Seite. Oft wird dann eine simple Seite angezeigt mit dem Hinweis dass die Seite nicht verfügbar ist. Etwas mehr Informationen können da hilfreich sein. Besonders wenn eine Seite einem kompletten Redesign unterzogen wurde, kommt es vor, dass Google Besucher auf nicht vorhandene Seiten schickt. In diesem Tutorial geht es um die Anpassung der &#8220;Standard 404-Seite&#8221;. </p>
<p>Concrete5 erlaubt es, ohne grossen Aufwand die 404-Seite anzupassen. Allerdings gibt es ein paar Dinge die man kennen muss. Als Ausgangslage dient diese Seite &#8211; die Standard Concrete5 404-Seite:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2010/01/pagenotfound.png"><img src="http://www.codeblog.ch/wp-content/uploads/2010/01/pagenotfound-300x194.png" alt="pagenotfound" title="pagenotfound" width="300" height="194" class="alignnone size-medium wp-image-426" /></a> </p>
<p><span id="more-425"></span></p>
<p>Wie man sieht, wird standardmässig das Concrete5 Dashboard Layout verwenden. Als erstes wollen wir unser eigenes Theme einsetzen. Dazu öffnen wir diese Datei: &#8220;config/site_theme_paths.php&#8221;. Es gibt bereits einige Beispiele welche auskommentiert sind, neu sollte die Datei jedoch folgendermassen aussehen:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>  
&nbsp;
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>_<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$v</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$v</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setThemeByPath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/page_not_found'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;yourtheme&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* 
	you can override system layouts here  - but we're not going to by default 
&nbsp;
	For example: if you would like to theme your login page with the Green Salad theme,
	you would uncomment the lines below and change the second argument of setThemeByPath 
	to be the handle of the the Green Salad theme &quot;greensalad&quot; 
&nbsp;
$v = View::getInstance();
&nbsp;
$v-&gt;setThemeByPath('/login', &quot;yourtheme&quot;);
 // $v-&gt;setThemeByPath('/403', &quot;yourtheme&quot;);
 // $v-&gt;setThemeByPath('/register', &quot;yourtheme&quot;);
 // $v-&gt;setThemeByPath('/dashboard', &quot;yourtheme&quot;);
&nbsp;
*/</span></pre></td></tr></table></div>

<p>Zeile 5 und 6 definieren unser eigenes Theme. &#8220;yourtheme&#8221; muss natürlich mti dem Namen des eigenen Themes ersetzt werden. Der Name ist identisch mit dem Verzeichnisname des Themes welches sich im Ordner &#8220;themes&#8221; befindet.</p>
<p>Es ist wichtig, dass das Theme eine Datei mit dem Namen view.php für &#8220;Single Pages&#8221; hat. Sie kann ungewähr folgendermassen aussehen:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>_<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">inc</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'elements/header.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id=&quot;content&quot;&gt;
&lt;div id=&quot;body&quot;&gt;
	   	&lt;!-- begin --&gt;
	   	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	   	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$innerContent</span><span style="color: #339933;">;</span>
	   	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	   	&lt;!-- end --&gt;&lt;/div&gt;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">inc</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'elements/footer.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>$innerContent enthält alle Informationen und muss zwingend ausgegeben werden. </p>
<p>Nachdem site_theme_paths.php gespeichert wurde, sollte die 404-Seite unser Layout übernommen haben. In meinem Fall sieht das folgendermassen aus:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2010/01/pagenotfound-custom.png"><img src="http://www.codeblog.ch/wp-content/uploads/2010/01/pagenotfound-custom-300x205.png" alt="pagenotfound-custom" title="pagenotfound-custom" width="300" height="205" class="alignnone size-medium wp-image-429" /></a></p>
<h2>Sitemap</h2>
<p>Machmal ist es hilfreich, wenn die 404-Seite die Seitenstruktur ausgibt. Auch das lässt sich relativ einfach umsetzen. Dazu muss von dieser Datei /concrete/single_pages/page_not_found.php hier eine Kopie erstellt werden /single_pages/page_not_found.php. Dadurch können wir den Inhalt der Datei anpassen, ohne im &#8220;Concrete5 Core&#8221; Änderungen vorzunehmen. Folgendes Beispiel zeigt den Code mit einer eingebauten Sitemap:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>_<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;h1 class=&quot;error&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Page Not Found'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No page could be found at this address.'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Area<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Main&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$a</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$bt</span> <span style="color: #339933;">=</span> BlockType<span style="color: #339933;">::</span><span style="color: #004000;">getByHandle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'autonav'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$bt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderBy</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'display_asc'</span><span style="color: #339933;">;</span>                    
<span style="color: #000088;">$bt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">displayPages</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'top'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$bt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">displaySubPages</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'all'</span><span style="color: #339933;">;</span>     
<span style="color: #000088;">$bt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">displaySubPageLevels</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'all'</span><span style="color: #339933;">;</span>                    
<span style="color: #000088;">$bt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'view'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>		
&nbsp;
&nbsp;
&nbsp;
&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> DIR_REL<span style="color: #000000; font-weight: bold;">?&gt;</span>/&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Back to Home'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;.</pre></td></tr></table></div>

<p>Die Zeilen 13 bis 20 verwenden den Autonav Block um eine Sitemap auszugeben. Mehr braucht&#8217;s nicht! In meinem Fall sieht die Seite so aus:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2010/01/pagenotfound-sitemap.png"><img src="http://www.codeblog.ch/wp-content/uploads/2010/01/pagenotfound-sitemap-300x203.png" alt="pagenotfound-sitemap" title="pagenotfound-sitemap" width="300" height="203" class="alignnone size-medium wp-image-432" /></a></p>
<p>Etwas überflüssig in meinem Fall, je nach Struktur/Seite aber vielleicht ganz nützlich.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2010/01/concrete5-custom-404-page/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Bilder in der Navigation</title>
		<link>http://www.codeblog.ch/de/2009/12/image-navigation-items/</link>
		<comments>http://www.codeblog.ch/de/2009/12/image-navigation-items/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 09:01:59 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Autonav]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=405</guid>
		<description><![CDATA[Concrete5 Navigation mit Bildern &#8211; der autonav Block erlaubt es sehr einfach und schnell eine hierarchische Seitenstruktur zur Navigation einzufügen. Sollen jedoch nicht Text-Links, sondern Bilder angeklickt werden, braucht es etwas mehr Arbeit. In diesem Tutorial werde ich ein &#8220;Custom Template&#8221; für den autonav Block erstellen, welches ein Attribut von einer Seite ausliest um ein [...]]]></description>
			<content:encoded><![CDATA[<p>Concrete5 Navigation mit Bildern &#8211; der autonav Block erlaubt es sehr einfach und schnell eine hierarchische Seitenstruktur zur Navigation einzufügen. Sollen jedoch nicht Text-Links, sondern Bilder angeklickt werden, braucht es etwas mehr Arbeit.</p>
<p>In diesem Tutorial werde ich ein &#8220;Custom Template&#8221; für den autonav Block erstellen, welches ein Attribut von einer Seite ausliest um ein Bild anstelle des Textes anzuzeigen.</p>
<p><span id="more-405"></span></p>
<h2>Seiten Attribute</h2>
<p>Mit Concrete5 können verschiedene Attribute einer Seite hinzugefügt werden. Damit kann man Meta-Tags, Notizen, Tags, Thumbnails oder eben auch Bilder für die Navigation verwalten. Als erstes müssen wir zwei neue Attribute erstellen. Eines wo wir das Bild auswählen können, wenn die Seite inaktiv ist und eines wenn die Seite aktiv ist.</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/12/1_page_attribute.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/12/1_page_attribute-300x174.png" alt="1_page_attribute" title="1_page_attribute" width="300" height="174" class="alignnone size-medium wp-image-406" /></a></p>
<p>Die roten Stellen sind entscheidend:</p>
<ul>
<li>Typ muss &#8220;Image/File&#8221; sein</li>
<li>Das &#8220;Handle&#8221; ist wichtig, wir benötigen es später im Template</li>
<li>Der Name ist nur informativ</li>
</ul>
<h2>Bilder zuweisen</h2>
<p>Wir haben nun zwei neue Attribute. Wie auf diesem Screenshot gezeigt, können wir dort Bilder zuweisen:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/12/2_set_pictures.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/12/2_set_pictures-300x186.png" alt="2_set_pictures" title="2_set_pictures" width="300" height="186" class="alignnone size-medium wp-image-407" /></a></p>
<ul>
<li>In der &#8220;Sitemap&#8221; die gewünschte Seite suchen und &#8220;Properties&#8221; auswählen</li>
<li>Unter &#8220;Custom Fields&#8221; können wir nun die beiden Felder für diese Seite aktivieren</li>
<li>Nun die beiden Bilder für die Navigation auswählen</li>
</ul>
<p>Das Gleiche bitte nun für alle Seiten machen wo kein Text sondern ein Bild in der Navigation erscheinen soll. Dies ist übrigens etwas das auch ein End-User machen kann. Dank den Seiten-Attributen kann ein End-User sogar Navigationselemente mit grafischem Text selber hinzufügen.</p>
<h2>Custom Template für den Autonav Block</h2>
<p>Wer mit dem Stichwort &#8220;Custom Template&#8221; nichts anfangen kann, sollte vermutlich zuerst dieses Tutorial durchlesen: <a href="http://www.codeblog.ch/de/2009/03/concrete5-templates/">http://www.codeblog.ch/de/2009/03/concrete5-templates/</a>.</p>
<p>Um ein neues Custom Template für den Autonav Block anzulegen, können wir ganz einfach von dieser Datei /concrete/blocks/autonav/view.php eine Kopie hier ablegen: /blocks/autonav/templates/image_navigation.php. Die Verzeichnisse autonav und templates müssen vermutlich zuerst erstellt werden.</p>
<p>In Zeile 55 sollte dieser Code zu finden sein. Je nach Concrete5 Version kann sich das natürlich ändern.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollectionID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$_c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollectionID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;li class=&quot;nav-selected nav-path-selected&quot;&gt;&lt;a class=&quot;nav-selected nav-path-selected&quot; href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pageLink</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ni</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollectionID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$selectedPathCIDs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;li class=&quot;nav-path-selected&quot;&gt;&lt;a class=&quot;nav-path-selected&quot; href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pageLink</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ni</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;li&gt;&lt;a href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pageLink</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ni</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Mit etwas HTML und PHP Kenntnissen erkennen wir bereits wo der Link-Text ausgegeben wird. $ni->getName(). Dies ist auch die Stelle wo wir nun ein Bild, falls vorhanden, ausgeben wollen.</p>
<p>Wir ersetzen $ni->getName() also mit Variablen und prüfen vorgängig ob das Seiten-Attribut einen Wert hat und weisen anschliessend ein img-Tag zu.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$linkTextActive</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ni</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$linkTextInactive</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ni</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$picOn</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pic_on'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$picOff</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pic_off'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$picOn</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$linkTextActive</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;img src=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$picOn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getURL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; alt=&quot;'</span> <span style="color: #339933;">.</span> linkTextActive <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;/&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$picOff</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$linkTextInactive</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;img src=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$picOff</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getURL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; alt=&quot;'</span> <span style="color: #339933;">.</span> linkTextInactive <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;/&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollectionID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$_c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollectionID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;li class=&quot;nav-selected nav-path-selected&quot;&gt;&lt;a class=&quot;nav-selected nav-path-selected&quot; href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pageLink</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$linkTextActive</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollectionID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$selectedPathCIDs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;li class=&quot;nav-path-selected&quot;&gt;&lt;a class=&quot;nav-path-selected&quot; href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pageLink</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$linkTextActive</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;li&gt;&lt;a href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pageLink</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$linkTextInactive</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<ul>
<li>Line 1,2: Die neuen Variablen</li>
<li>Line 4,5: Attribut-Wert auslesen</li>
<li>Line 7-12: Prüft ob das Attribut einen Wert hat und generiert das img-Tag</li>
</ul>
<p>Jetzt kann ein autonav Block eingefügt werden, alle Einstellungen vornehmen und nachdem der Block hinzugefügt wurde, erneut anklicken und &#8220;Set Custom Template&#8221; wählen. Hier sollte nun unser neues Custom Template erscheinen.</p>
<p>Wenn alles funktioniert hat, sollte nun eine Navigation mit Bildern erscheinen:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/12/example.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/12/example-300x165.png" alt="example" title="example" width="300" height="165" class="alignnone size-medium wp-image-417" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2009/12/image-navigation-items/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Concrete5 &#8211; Form styling</title>
		<link>http://www.codeblog.ch/de/2009/07/concrete5-form-layout/</link>
		<comments>http://www.codeblog.ch/de/2009/07/concrete5-form-layout/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 11:12:51 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=368</guid>
		<description><![CDATA[Concrete5 bietet einen netten Form Block, mit dem man Formulare in wenigen Sekunden erstellen. Dies ohne HTML oder PHP Kenntnisse. Unglücklicherweise lässt sich der HTML Code davon, nur schlecht mit CSS anpassen. In diesem Tutorial zeige ich, wie man ein Formular in diesem Stil erstellen kann: Custom Templates Das Stichwort &#8220;Custom Templates&#8221; sollte bekannt sein, [...]]]></description>
			<content:encoded><![CDATA[<p>Concrete5 bietet einen netten Form Block, mit dem man Formulare in wenigen Sekunden erstellen. Dies ohne HTML oder PHP Kenntnisse. Unglücklicherweise lässt sich der HTML Code davon, nur schlecht mit CSS anpassen. In diesem Tutorial zeige ich, wie man ein Formular in diesem Stil erstellen kann:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/07/pic2.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/07/pic2-300x257.png" alt="Styles Form" title="Styles Form" width="300" height="257" class="alignnone size-medium wp-image-370" /></a></p>
<p><span id="more-368"></span></p>
<h2>Custom Templates</h2>
<p>Das Stichwort &#8220;Custom Templates&#8221; sollte bekannt sein, ansonsten bitte zuerst diesen Artikel durchlesen: <a href="http://www.codeblog.ch/2009/03/concrete5-templates/">http://www.codeblog.ch/2009/03/concrete5-templates/</a>. Kurz zusammengefasst: Concrete5 erlaubt es, mittels &#8220;Custom Templates&#8221; sämtliche Blöcke in ihrem Erscheinungsbild anzupassen, falls mit CSS nicht genügend Möglichkeiten zur Verfügung stehen sollten.</p>
<h2>Core Änderungen</h2>
<p>Der Controller des Form Blocks hat eine kleine Unschönheit, welche das &#8220;stylen&#8221; mit CSS etwas erschwert. Da keine Funktionalität daran hängt, hab ich in diesem Fall den Code im &#8220;Core&#8221; direkt modifiziert. Ev. wird das in einer zukünftigen Version geändert. Es betrifft die Datei &#8220;concrete/blocks/form/controller.php&#8221; in der Zeile 667:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/07/pic1.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/07/pic1-300x46.png" alt="pic1" title="pic1" width="300" height="46" class="alignnone size-medium wp-image-369" /></a></p>
<p>Die Anweisung &#8216;style=&#8221;width:95%&#8221;&#8216; ist zu entfernen.</p>
<h2>Das Standard Layout</h2>
<p>Wird ein Formular mit Concrete5 erstellt, sieht es standardmässig so aus:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/07/pic3.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/07/pic3-300x167.png" alt="pic3" title="pic3" width="300" height="167" class="alignnone size-medium wp-image-371" /></a></p>
<p>Es funktioniert, sieht aber nicht wirklich hübsch aus.</p>
<h2>Das neue Layout</h2>
<p>In diesem Tutorial zeige ich, wie man ein Formular erstellen kann, bei dem die Labels nicht neben den Eingabefeldern stehen, sondern gleich im Feld. Dies kann besonders nützlich sein, wenn wenig Platz vorhanden ist, und ein grosses Formular einzufügen ist. Das PHP Template view.php</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>    
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>_<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$survey</span><span style="color: #339933;">=</span><span style="color: #000088;">$controller</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$miniSurvey</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> MiniSurvey<span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$miniSurvey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">frontEndMode</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div class=&quot;ccm-form&quot; id=&quot;ccm-form-id-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bID</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$invalidIP</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div class=&quot;ccm-error&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$invalidIP</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;form enctype=&quot;multipart/form-data&quot; id=&quot;miniSurveyView<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bID</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;miniSurveyView&quot; method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'submit_form'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'surveySuccess'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'qsid'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$survey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionSetId</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id=&quot;msg&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$survey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thankyouMsg</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>   <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$formResponse</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id=&quot;msg&quot;&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$formResponse</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;?php</span>  
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$errors</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$errors</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$errors</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;div class=&quot;error&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$error</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;
'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;input name=&quot;qsID&quot; type=&quot;hidden&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span>  <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$survey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionSetId</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
	&lt;input name=&quot;pURI&quot; type=&quot;hidden&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span>  <span style="color: #000088;">$pURI</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>   	
	<span style="color: #000088;">$questionsRS</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$miniSurvey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadQuestions</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$survey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionSetId</span><span style="color: #339933;">,</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$surveyBlockInfo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$miniSurvey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMiniSurveyBlockInfoByQuestionId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$survey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionSetId</span><span style="color: #339933;">,</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bID</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$showEdit</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$hideQIDs</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$questionRow</span><span style="color: #339933;">=</span><span style="color: #000088;">$questionsRS</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$questionRow</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'qID'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hideQIDs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$msqID</span><span style="color: #339933;">=</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$questionRow</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'msqID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$requiredClass</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$questionRow</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'required'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>?<span style="color: #0000ff;">' required '</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$requiredSymbol</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$questionRow</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'required'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>?<span style="color: #0000ff;">' *'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;div class=&quot;ccm-form-element'</span><span style="color: #339933;">.</span><span style="color: #000088;">$requiredClass</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Question'</span><span style="color: #339933;">.</span><span style="color: #000088;">$msqID</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$questionRow</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'question'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$requiredSymbol</span><span style="color: #339933;">;</span>				
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$miniSurvey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadInputType</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$questionRow</span><span style="color: #339933;">,</span>showEdit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;
&quot;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span>	
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$surveyBlockInfo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'displayCaptcha'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>		
		<span style="color: #000088;">$captcha</span> <span style="color: #339933;">=</span> Loader<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'validation/captcha'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>				
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>ccm-form-captcha<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;div class=&quot;required&quot;&gt;'</span><span style="color: #339933;">;</span>		
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;input type=&quot;text&quot; value=&quot;Sicherheitscode hier eingeben&quot; name=&quot;ccmCaptchaCode&quot; class=&quot;ccm-input-captcha&quot;/&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Please note that we need to style our captcha, we therefore create it manually!</span>
		<span style="color: #666666; font-style: italic;">//$captcha-&gt;showInput();</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;
&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&lt;div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$captcha</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;
&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;
&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;div style=&quot;clear:both&quot;&gt;&lt;/div&gt;
'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;input class=&quot;formBlockSubmitButton button&quot; name=&quot;Submit&quot; type=&quot;submit&quot; value=&quot;senden&quot; /&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">?&gt;</span> 
&lt;/form&gt;&lt;/div&gt;</pre></td></tr></table></div>

<p>Ich werde nicht jede Zeile erklären, da dies etwas umfangreich wäre. Ich geh davon aus, dass PHP Kenntnisse vorhanden sind.<br />
Kurz aufgelistet, was geändert wurde:</p>
<ul>
<li>Einige Methoden vom Controller werden neu aus der View aufgerufen</li>
<li>Das Tabellen Layout durch DIV&#8217;s ersetzt</li>
<li>CSS Klassen eingefügt, welche für die JavaScript Checks verwendet werden</li>
<li>$_REQUEST angepasst, damit die Labels im &#8220;value&#8221; Attribute ausgegeben werden</li>
</ul>
<p>Nun haben wir ein Formular, bei dem die Labels in den Eingabefeldern ausgegeben werden. Wir müssen nun aber auch sicherstellen, dass diese vordefinierten Werte ersettz werden können, ansonsten kann es passieren, dass Formulare mit diesen Werten abgeschickt werden können.<br />
Dazu werden verschiedene Events geprüft:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView input[type=text], textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span>onEnterField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView input[type=text], textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span>onEnterField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView input[type=text], textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span>onLeaveField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Sobald ein Benutzer ein Feld aktiviert oder verlässt, werden diese Funktionen aufgerufen. Dort wird geprüft, ob der Wert zu ersetzen ist oder nicht:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> onEnterField<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">origLabel</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">origLabel</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">origLabel</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">origLabel</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.formError&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> onLeaveField<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">origLabel</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">origLabel</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Zusätzlich kommen ein paar clientseitige Checks dazu, um dem Benutzer sofort einen Hinweis betreffend nicht ausgefüllten Feldern ausgeben zu können.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView input[type=text], textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span>onEnterField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView input[type=text], textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span>onEnterField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView input[type=text], textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span>onLeaveField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> formErrors <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.formError'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[type=text], textarea'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'origLabel'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> undefined <span style="color: #339933;">||</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'origLabel'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;required&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				formErrors<span style="color: #339933;">++;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">before</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'
&lt;div class=&quot;formError&quot; id=&quot;formError'</span><span style="color: #339933;">+</span>formErrors<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; style=&quot;height:18px;color:red;font-size:10px;display:none;&quot;&gt;Bitte Wert eingeben:&lt;/div&gt;
'</span><span style="color: #009900;">&#41;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#formError&quot;</span> <span style="color: #339933;">+</span> formErrors<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>					
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>formErrors <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">else</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Wir in einem Feld kein Wert eingegeben, wird ganz einfach oberhalb davon eine entsprechende Meldung ausgegeben.</p>
<p>Das Template enthält einige CSS Anweisungen, welche ich hier nicht weiter erkläre. Mit grundlegenden CSS Kenntnissen sind diese problemlos zu verstehen und können auch entsprechend angepasst/erweitert werden. Sämtliche Dateien finden sich in folgendem ZIP:</p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2009/07/codeblog.zip'>Template herunterladen</a></p>
<p>Den Inhalt der ZIP Datei ins Verzeichnis &#8220;blocks/form/templates&#8221; entpacken. Die Verzeichnisse &#8220;form&#8221; und &#8220;templates&#8221; müssen ev. vorgängig erstellt werden!<br />
Viel Spass!</p>
 <p><a href="http://www.codeblog.ch/?flattrss_redirect&amp;id=368&amp;md5=fc0877a0bb382a8dbee13963e8cb7596" title="Flattr" target="_blank"><img src="http://www.codeblog.ch/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2009/07/concrete5-form-layout/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Vorschau Text mit PHP</title>
		<link>http://www.codeblog.ch/de/2009/06/smart-text-trimming-with-php/</link>
		<comments>http://www.codeblog.ch/de/2009/06/smart-text-trimming-with-php/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 12:56:46 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[trim]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=353</guid>
		<description><![CDATA[Möchte man einen kurzen Vorschautext in PHP erstellen, der einen Anriss des effektiven Textes zeigt, so wird man wohl oft die einfachste Variante gewählt haben, und einfach nach einer Anzahl definierten Zeichen abgeschnitten haben. Dies generiert jedoch ein unschönes Ergebnis, wenn man eine proportionale Schrift verwendet. Sämtliche Text haben markant unterschiedliche Längen wie auf diesem [...]]]></description>
			<content:encoded><![CDATA[<p>Möchte man einen kurzen Vorschautext in PHP erstellen, der einen Anriss des effektiven Textes zeigt, so wird man wohl oft die einfachste Variante gewählt haben, und einfach nach einer Anzahl definierten Zeichen abgeschnitten haben. Dies generiert jedoch ein unschönes Ergebnis, wenn man eine proportionale Schrift verwendet. Sämtliche Text haben markant unterschiedliche Längen wie auf diesem Bild gezeigt wird:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/06/text-trimming.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/06/text-trimming-300x255.png" alt="text-trimming" title="text-trimming" width="300" height="255" class="alignnone size-medium wp-image-354" /></a></p>
<p>Dieser Artikel zeigt einen einfachen Ansatz, diese Problematik etwas eleganter zu lösen!</p>
<p><span id="more-353"></span></p>
<h2>Textlänge messen</h2>
<p>PHP bietet verschiedene Methoden um die Länge eines Textes zu messen. Zum Beispiel die Methode <a target="_blank" href="http://ch2.php.net/manual/en/function.imagefontwidth.php">ImageFontWidth</a> welche die Länge der PHP internen Schriften einfach und gut messen kann. Möchte man ein einfaches Captcha erstellen, das die internen Schriften verwendet, ist diese Methode sicherlich eine gute Wahl.</p>
<p>Allerdings gibt&#8217;s noch eine andere Methode, welche die komplette &#8220;Bounding Box&#8221; errechnet. Sie lautet <a href="http://ch2.php.net/manual/en/function.imagettfbbox.php">imagettfbbox</a>. Der Rückgabe-Wert ist eine Array welches sämtliche Werte für die &#8220;Bounding Box&#8221; enthält.</h2>
<p>Die Methode</h2>
<p>Wie zu Beginn des Artikels gezeigt, wollte ich eine Methode die den Text kürzt und am Ende einen weiteren Text (in diesem Fall &#8220;&#8230;&#8221;) anhängt um zu zeigen, dass der Text nicht vollständig ist.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> trim_by_width<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span><span style="color: #000088;">$font_file</span><span style="color: #339933;">,</span><span style="color: #000088;">$font_size</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span><span style="color: #000088;">$append_string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'...'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$append_string_box</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagettfbbox</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$font_size</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$font_file</span><span style="color: #339933;">,</span><span style="color: #000088;">$append_string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$append_string_width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$append_string_box</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$str_len</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;=</span><span style="color: #000088;">$str_len</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$trimmed_text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$bounding_box</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagettfbbox</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$font_size</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$font_file</span><span style="color: #339933;">,</span><span style="color: #000088;">$trimmed_text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$trimmed_text_width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bounding_box</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_text_width</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$append_string_width</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$str_to_return</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_text</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_text_width</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$str_len</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$str_to_return</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$append_string</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$str_to_return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$trimmed_text</span> <span style="color: #339933;">=</span> trim_by_width<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font_file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font_size</span><span style="color: #339933;">,</span> <span style="color: #000088;">$append_string</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>$text:<br />
<code>Der Text der zu kürzen </code></p>
<p>$width:<br />
<code>Die maximale Länge des Textes in Pixel!</code></p>
<p>$font_file:<br />
<code>Die True Type Schriftendatei</code></p>
<p>$font_size:<br />
<code>Die Schriftgrösse. Bitte beachten Sie, dass die Einheiten je nach GD Version anders sind. GD1 verwendet Pixel, GD2 hingegen Punkte./code></p>
<p>$append_string:<br />
<code>Ein optionaler String welcher bei gekürzten Texten angehängt wird. Standardmässig "..."</code></p>
<h2>Beispiel</h2>
<p>Sie können die Methode nach folgendem Schema aufrufen:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> trim_by_width<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'this is a long text'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">55</span><span style="color: #339933;">,</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/verdana.ttf'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Das Script geht davon aus, dass sich die Datei verdana.ttf im gleichen Verzeichnis wie das PHP Script befindet. Anschliessend wird der Text nach 55 Pixel gekürzt und ausgegeben.</p>
<p>Fertig!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2009/06/smart-text-trimming-with-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Concrete5 &#8211; Team Datenbank in Tabelle</title>
		<link>http://www.codeblog.ch/de/2009/06/concrete5-staff-table/</link>
		<comments>http://www.codeblog.ch/de/2009/06/concrete5-staff-table/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 10:53:30 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[columns]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[person]]></category>
		<category><![CDATA[staff]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=334</guid>
		<description><![CDATA[In vielen Fällen soll eine Internetseite Elemente enthalten, die in zwei Spalten dargestellt werden sollen. In diesem Tutorial beschreibe ich einen sehr einfachen Block, um ein Bild einer Person anzuzeigen, so dass die Beschreibung rechts vom Bild dargestellt wird. Das Ergebnis schaut folgendermassen aus: Tabellenlayouts Ich werde hier nicht in die Details über Tabellen-Layouts eingehen. [...]]]></description>
			<content:encoded><![CDATA[<p>In vielen Fällen soll eine Internetseite Elemente enthalten, die in zwei Spalten dargestellt werden sollen. In diesem Tutorial beschreibe ich einen sehr einfachen Block, um ein Bild einer Person anzuzeigen, so dass die Beschreibung rechts vom Bild dargestellt wird. </p>
<p>Das Ergebnis schaut folgendermassen aus:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/06/staff1.jpg"><img src="http://www.codeblog.ch/wp-content/uploads/2009/06/staff1-300x212.jpg" alt="staff1" title="staff1" width="300" height="212" class="alignnone size-medium wp-image-335" /></a></p>
<p><span id="more-334"></span></p>
<h2>Tabellenlayouts</h2>
<p>Ich werde hier nicht in die Details über Tabellen-Layouts eingehen. Nur ganz grundlegend &#8211; das Tag &#8220;table&#8221; sollte nicht für Layouts verwendet werden. Inzwischen ist div &#038; css der korrekte Weg.<br />
Concrete5 erlaubt es uns zwei editierbare Bereiche zu erstellen, womit wir quasi ein 2-spaltiges Layout hätten. Allerdings ergibt sich in unserem Fall das Problem, dass das Bild in der linken Spalte wäre, der Text in der rechten. Damit beide Elemente immer auf der gleichen Höhe beginnen, müssten wir eine fixe Höhe mitgeben, was in den meisten Fällen wohl nicht optimal ist.</p>
<p>Ich werde also eine Lösung beschreiben, die in einem einspaltigen Layout verwendet werden kann, und dabei keine html Tabellen verwendet.</p>
<h2>Der Personen Block</h2>
<p>Der Block enthält lediglich zwei Elemente. Ein Bild und ein Textfeld um eine Beschreibung einzugeben.</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/06/staff2.jpg"><img src="http://www.codeblog.ch/wp-content/uploads/2009/06/staff2-294x300.jpg" alt="staff2" title="staff2" width="294" height="300" class="alignnone size-medium wp-image-336" /></a></p>
<p>Die HTML Ausgabe sieht folgendermassen aus:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;ccm-person&quot;&gt;
   &lt;div class=&quot;ccm-person-image&quot;&gt;&lt;img src=&quot;http://myserver/remo.jpg&quot; alt=&quot;&quot;&gt;&lt;/div&gt;
   &lt;div class=&quot;ccm-person-description&quot;&gt;Lorem ipsum dolor sit ame.&lt;/div&gt;
   &lt;div style=&quot;clear:both&quot;&gt;&lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>Bitte beachten, dass ich am Ende eine &#8220;inline CSs-Anweisung&#8221; eingebaut habe. Dies wenn möglich durch eine Klasse aus dem gewählten Theme ersetzen. Ich hab hier lediglich zu Demonstrationszwecken kein ganzes Theme veröffentlicht, damit der Code kurz und lesbar bleibt.</p>
<p>Ohne weitere CSS-Anweisungen wird der Text unterhalb des Bildes dargestellt. Da wir aber ein zweispaltiges Layout haben wollen, fügen wir unsere CSS Datei aus dem Theme ein paar Zeilen hinzu:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.ccm-person-image</span> <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">80px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.ccm-person-description</span> <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">385px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Dies muss unter Umständen dem Theme angepasst werden.<br />
Am besten einfach den Block herunterladen und loslegen!</p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2009/06/person.zip'>Block herunterladen</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2009/06/concrete5-staff-table/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Concrete5 Templates</title>
		<link>http://www.codeblog.ch/de/2009/03/concrete5-templates/</link>
		<comments>http://www.codeblog.ch/de/2009/03/concrete5-templates/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 16:52:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=188</guid>
		<description><![CDATA[Concrete5 Templates erstellen ENGLISH Das CMS System Concrete5 bietet die Möglichkeit, für bestehende Blocks aus dem Core, dem Teil von Concrete5 der nicht verändert werden sollte, ein eigenes Template zu erstellen. Dadurch hat man die Möglichkeit das Layout komplett anzupassen, sollte CSS nicht mehr genügen. In diesem Beispiel, wollen wir den &#8220;Page List&#8221; Block, anpassen. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Concrete5 Templates erstellen  <a href="http://www.codeblog.ch/en/2009/03/concrete5-templates/">ENGLISH</a></strong></p>
<p>Das CMS System Concrete5 bietet die Möglichkeit, für bestehende Blocks aus dem Core, dem Teil von Concrete5 der nicht verändert werden sollte, ein eigenes Template zu erstellen. Dadurch hat man die Möglichkeit das Layout komplett anzupassen, sollte CSS nicht mehr genügen.</p>
<p><span id="more-188"></span></p>
<p>In diesem Beispiel, wollen wir den &#8220;Page List&#8221; Block, anpassen. Mit Hilfe des Page List Blocks, ist es möglich, eine Liste von Seiten zu erstellen, die sich selber erweitert, sollte eine neue Unterseite hinzugefügt werden. Eine News Seite zum Beispiel. In diesem Tutorial hab ich eine simple Liste von Seiten erstellt. Die Struktur sieht wie folgt aus:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2009/03/delte0.png"><br />
<img src="http://www.codeblog.ch/wp-content/uploads/2009/03/delte0-300x201.png" alt="delte1" title="delte1" width="300" height="201" class="alignnone size-medium wp-image-190" /></a></p>
<p>Die beiden Seite &#8220;Unterseite A&#8221; und &#8220;Unterseite B&#8221; sollen in einer Liste ausgegeben werden. Dazu müssen wir auf der übergeordneten Seite &#8220;Liste&#8221; einen Page List Block einfügen:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/03/delte2.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/03/delte2-300x201.png" alt="delte2" title="delte2" width="300" height="201" class="alignnone size-medium wp-image-191" /></a></p>
<p>Anschliessend können wir unsere Liste bereits anschauen:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/03/delte3.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/03/delte3-300x201.png" alt="delte3" title="delte3" width="300" height="201" class="alignnone size-medium wp-image-192" /></a></p>
<p>Das Layout ist nicht perfekt, können wir mit CSS anpassen! Was aber wenn wir ein Thumbnail &#8211; ein kleines Bild &#8211; einfügen wollen? Ein Template erstellen!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2009/03/concrete5-templates/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Einstieg in Ruby (on Rails)</title>
		<link>http://www.codeblog.ch/de/2009/02/einstieg-in-ruby/</link>
		<comments>http://www.codeblog.ch/de/2009/02/einstieg-in-ruby/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 12:34:44 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=160</guid>
		<description><![CDATA[Schon länger liest und hört man viel von Ruby, vorallem von Ruby on Rails. Man will sich als Programmierer ja schliesslich auf dem laufenden halten, so auch ich. Die Prioritäten haben den Ruby Start oft verschoben, als nun aber Redmine bei einem Projekt zum Einsatz kommen wird, und je nach Ergebnis in Zukunft auch bei [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.codeblog.ch/wp-content/uploads/2009/02/logo.gif" alt="" title="logo" width="331" height="119" class="alignnone size-medium wp-image-166" /></p>
<p>Schon länger liest und hört man viel von <a href="http://www.ruby-lang.org" target="_blank">Ruby</a>, vorallem von Ruby on Rails. Man will sich als Programmierer ja schliesslich auf dem laufenden halten, so auch ich. Die Prioritäten haben den Ruby Start oft verschoben, als nun aber <a href="http://www.redmine.org" target="_blank">Redmine</a> bei einem Projekt zum Einsatz kommen wird, und je nach Ergebnis in Zukunft auch bei anderen Projekten, wurde es doch Zeit mit Ruby on Rails zu starten!</p>
<p><span id="more-160"></span></p>
<p><strong>Allgemein</strong></p>
<p>Ich versuche eigentlich immer, Dinge am Anfang selber zu erforschen. Nicht das ich das Gefühl habe, dass dies zum perfekten Ergebnis führt, aber wenn man am Anfang ein paar Stunden investiert und einige Probleme ohne fremde Hilfe oder Literatur lösen kann, so versteht man die Philosophie hinter einer Technologie besser.</p>
<p>Bei Ruby hat auch dies bis zu einem gewissen Punkt funktioniert, bei Rails sind dann aber doch einige Fragen aufgetaucht, bei der man mindestens ein Tutorial lesen sollte. Alles der Reihe nach&#8230;</p>
<p><strong>Installation</strong></p>
<p>Installationsanleitungen zu Ruby und Rails gibt es zahlreiche. Leider scheint es aber immer ein paar Unterschiede bei der Installation zu geben. Ich hatte mir hier erhofft, dass eine so hoch gelobte Sprache eine ebenso solide Installationsroutine mitliefert.</p>
<p>Unter Windows scheint <a href="http://rubyforge.org/projects/instantrails/" target="_blank">InstantRails</a> sich bewährt zu haben. Dies mag für einen Einsteiger sehr praktisch sein, bekommt man doch gleich alles was man für den Ruby Start benötigt.</p>
<p>Da ich aber zu den Leuten gehöre, die nicht nur Auto fahren, sondern auch gerne verstehen wieso das Auto überhaupt fährt, wollte ich alles selber installieren. Zudem arbeite ich mit einem Debian Linux auf einem alten Mini Mac PPC, Windows läuft hier nur über QEMU und das mit einer völlig inakzeptablen Performance.</p>
<p>Google hat mir hier als erstes einen älteren Artikel angezeigt, der erklärt wie man Ruby mit Apache2 unter Debian installieren kann. Viele Ruby Anhänger bevorzugen lighttpd und einige, wie ich, arbeiten auch mit nginx. Apache2 war aber bereits installiert und ob nginx nun etwas weniger Speicher benötigt, lighttpd etwas schneller ist- funktionieren sollte es ja mit Apache2 auch und das ist bei einem Einstieg ja wohl die Hauptsache.</p>
<p>Der Artikel aus dem Jahr 2006 &#8211; <a href="http://www.technixblog.de/archives/linux/debian/tutorial-ruby-on-rails-fur-debian-sarge" target="_blank">http://www.technixblog.de/archives/linux/debian/tutorial-ruby-on-rails-fur-debian-sarge</a> hat bei mir einwandfrei geklappt, abgesehen von zwei kleinen Modifikationen:</p>
<ul>
<li>Ich musste das rewrite Module explizit aktivieren “ln -s /etc/apache2/mods-available/rewrite.load”</li>
<li>Ich musste .htaccess anpassen, und diese Zeile am Anfang einfügen: “RewriteEngine On”</li>
</ul>
<p>Anschliessend hatte ich aber bereits eine komplett lauffähige Ruby on Rails Umgebung.</p>
<p><strong>Literatur</strong></p>
<p><strong></strong>Wie anfänglich beschrieben, funktioniert Ruby als Programmiersprache sehr intuitiv. Vieles funktioniert einfach, am besten einfach mal schreiben und schauen ob eine Fehlermeldung ausgegeben wird. Das Design der Sprache scheint wirklich durchdacht zu sein.</p>
<p>Bei Rails gibt es allerdings ein paar Kleinigkeiten wie zum Beispiel die Generatoren, die man einfach kennen muss. Ob man hier ein Tutorial, ein Magazin oder gleich ein Buch verwendet, sei jedem selbst überlassen.</p>
<p>Ich hatte mir, da ich gerade eine längere Zugfahrt vor mir hatte, das Magazin &#8220;RailsWay&#8221; gekauft. Ein paar Artikel die einen ersten Eindruck geben, viel Inhalt ist aber nicht vorhanden. Ist allerdings auch schwierig sämtliche Bedürfnisse von Rails Entwicklern abzudecken. Allerdings war im Magazin eine DVD beigelegt mit einigen PDF&#8217;s. Unteranderen das OpenBook &#8220;Praxiswissen Ruby on Rails&#8221;.</p>
<p>Man findet dieses Buch übrigens auch im Internet &#8211; <a href="http://www.oreilly.de/german/freebooks/rubyonrailsbasger/" target="_blank">http://www.oreilly.de/german/freebooks/rubyonrailsbasger/</a></p>
<p>Die Sprache des Autors, Denny Carl, ist einfach zu lesen und teilweise auch relativ unterhaltsam. Das Buch beginnt ziemlich am Anfang, so dass auch Personen ohne grosse Programmiererfahrung ihre ersten Schritte meistern können. Da ich mich aber doch ein Weilchen mit Programmiersprachen auseinandergesetzt habe, hab ich die ersten Seiten im Tempo eines Schnellzuges, davon kommt übrigens auch der Name &#8220;Ruby on Rails&#8221;, gelesen.</p>
<p>Man muss im PDF bis zur Seite 165 gehen, um den Einstieg in Rails zu finden. Ein paar Hintergrundinformationen und anschliessend ein hübsches Beispiel, das Schritt für Schritt erklärt wird. Einziger Kritikpunkt hier &#8211; der Autor bezieht sich relativ stark auf die Entwicklungsumgebung RadRails. Diese ist zwar ganz hübsch, wenn man aber wie ich alles verstehen möchte, so wäre es teilweise praktisch, wenn man die Befehlszeile auch lesen könnte. Die Generatoren von Ruby werden schliesslich standardmässig per Konsole gestartet.</p>
<p><strong>Konzept / Idee von Rails</strong></p>
<p>Ruby on Rails basiert einerseits auf dem MVC- und DRY-Konzept.</p>
<p>MVC steht für Model View und Controller und beschreibt eine Architektur von Software. Ich geh davon aus, dass dies bekannt ist, ansonsten empfehle ich an diesem Punkt ein Tutorial oder Buch zum Thema MVC zu lesen.</p>
<p>DRY steht für &#8220;Don&#8217;t repeat yourself&#8221;. Man soll die gleichen Dinge nicht mehrfach tun. Ganz einfach in der Theorie, Rails hat aber ein paar Tools die dieses Konzept unterstützen, wichtig an diesem Punkt ist vorallem, dass man versteht und verinnerlicht hat, dass Ruby on Rails Dinge nicht mehrfach tun möchte. So banal das klingt, so oft wird bei zahlreichen Projekten dagegeben verstossen.</p>
<p><i>Ein Beispiel: Wenn Sie mit CSS arbeiten, haben Sie sicherlich schon den Farbwert verändert, sei es die Schriftfarbe oder eine Hintergrundfarbe. Das mit das CI (Corporate Identity) stimmt, kommt diese Farbe oft an zahlreichen stellen vor, Sie schreiben also #A0B3EF ziemlich oft, CSS kennt keine Variablen. Dies mag jetzt vielleicht etwas übertrieben wirken, ist es doch wirklich kein Weltuntergang, dass man einen Farbwert mehrmals schreiben muss &#8211; einverstanden! Ruby on Rails wäre hier aber vermutlich weiter gegangen und hätte da einen anderen Weg gewählt. Nicht dass ich das wüsste, ich behaupte es lediglich! Nur zur Veranschaulichung wie und wo man Dinge doppelt tut.</i></p>
<p><strong>Hello World</strong></p>
<p>Etwas altbacken, aber ein &#8220;Hello World&#8221; gehört auch heute noch zu jedem Einsteiger Tutorial.</p>
<p>In der Installationsanleitung haben wir bereits ein Rails Projekt angelegt. Dazu haben wir diese Befehlszeile ausgeführt:</p>
<pre>rails /home/rails/meineApp</pre>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/02/rails1.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/02/rails1-475x329.png" alt="" title="rails1" width="475" height="329" class="alignnone size-medium wp-image-163" /></a></p>
<p>Es sollte eine längere Ausgaben von Informationen angezeigt werden, und hoffentlich keine Fehler.</p>
<p>Wo schreiben wir nun den Code? Wie ein paar Zeilen weiteroben erwäht, Rails bietet sogenannten &#8220;Generatoren&#8221;, die einen Basis-Code automatisch generieren können. In diesem Fall kann der Befehl zum Beispiel so aussehen:</p>
<pre>ruby script/generate controller SagHallo</pre>
<p>Auch hier sollten erneut ein paar Zeilen angezeigt werden, die erklären welche Dateien erstellt wurden.<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2009/02/geany2.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/02/geany2-475x363.png" alt="" title="geany2" width="475" height="363" class="alignnone size-medium wp-image-171" /></a></p>
<p>Adressen in Rails funktionieren generell nach diesem Prinzip:</p>
<pre>http://server/controller/action</pre>
<p>In unserem Fall also http://localhost/sag_hallo/sali</p>
<p>Den Controller haben wir ja gerade erst angelegt, was aber ist die &#8220;Action&#8221;? Ein Aufruf der Adresse zeigt uns auch gleich, dass wir da noch etwas vergessen haben:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2009/02/opera.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/02/opera-475x201.png" alt="" title="opera" width="475" height="201" class="alignnone size-medium wp-image-173" /></a></p>
<p>Da fehlt eine Action! Die gehört in den Controller und ist eigentlich nicht viel mehr als eine Methode.<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2009/02/geany3.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/02/geany3-475x363.png" alt="" title="geany3" width="475" height="363" class="alignnone size-medium wp-image-174" /></a></p>
<p>Action erstellt, nächster Versuch:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/02/opera2.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/02/opera2-475x201.png" alt="" title="opera2" width="475" height="201" class="alignnone size-medium wp-image-175" /></a></p>
<p>Auch nicht das was wir wollen! Wir arbeiten mit einem MVC Framework, wir haben bisher ja erst den Buchstaben &#8220;C&#8221; (Controller) angelegt, das &#8220;M&#8221; (Model) ist nicht zwingend, das &#8220;V&#8221; (View) hingegen schon, wir wollen ja schliesslich etwas anzeigen!</p>
<p>Wir erstellen also noch eine Datei:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2009/02/geany4.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/02/geany4-475x363.png" alt="" title="geany4" width="475" height="363" class="alignnone size-medium wp-image-176" /></a></p>
<p>Wenn wir nun die Seite öffnen, so sehen wir endlich etwas:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2009/02/opera4.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/02/opera4-475x201.png" alt="" title="opera4" width="475" height="201" class="alignnone size-medium wp-image-177" /></a></p>
<p>Damit die Seite nicht komplett statisch ist, hab ich noch die aktuelle Zeit ausgegeben.</p>
<p><strong>Fazit</strong></p>
<p>Die Installation hat etwas mehr Zeit in Anspruch genommen als geplant, ansonsten scheint Ruby on Rails wie Ruby selbst, sauber strukturiert und durchdacht aufgebaut worden zu sein.</p>
<p>Das praktische an Rails ist, dass man quasi zwangsweise die MVC Architektur verwenden muss. Zwang klingt negativ, ist es in diesem Fall aber selten. Ein gewisser Zwang führt dazu, dass sämtliche Entwickler &#8220;gleich arbeiten&#8221; &#8211; ob Sie wollen oder nicht.</p>
<p>Viele Leute vergleichen eine Programmiersprache wie &#8220;PHP&#8221; mit einem Framework wie &#8220;Ruby on Rails&#8221;. Bei diesem Punkt bin ich immer etwas skeptisch, schliesslich hat man ja schon als Kind gelernt, dass man nicht Äpfel mit Birnen vergleichen soll. PHP ohne Framework erlaubt es einen bunten Wildwuchs an Funktionen einzubauen, ohne dass man eine saubere Struktur aufbauen muss. Klar dass dann eine unschöne, umfangreiche und schlecht zu wartende Software entsteht.</p>
<p>Allerdings gibt es auch für Sprachen wie PHP MVC Frameworks. Mit <a href="http://www.cakephp.org">CakePHP</a> und <a href="http://codeigniter.com/">CodeIgniter</a> sind nur zwei der zahlreichen Frameworks genannt.</p>
<p>Positiv ans Ruby finde ich, dass Rails eigentlich fast so bekannt ist, wie Ruby selbst. Dies hat wohl dazu geführt, dass einige Programmierer die mit Ruby gestartet haben, gleich Rails verwendet haben, und so &#8220;schönere Applikationen&#8221; entwickelt haben.</p>
<p>Ob Ruby, PHP oder Java, mit allen Sprachen kann man gut strukturierte Software entwickeln. Ruby und Rails sind relativ moderne Technologien, so dass man sich nicht mit sämtlichen Altlasten rumschlagen muss. Dies ist sicherlich ein positiver Aspekt, ob es genügt, dass ich in Zukunft weniger C#, PHP, PL/SQL Code schreibe, wird sich zeigen.</p>
<p>Bis jetzt scheint es eine gute Alternative zu sein, allerdings hab ich bis jetzt noch nichts gefunden, dass ich mit anderen Sprachen nicht auch tun könnte, mit Ruby geht&#8217;s vielleicht teilweise eleganter, aber schliesslich habe ich in meiner Firma einiges an Know-How mit anderen Sprache aufgebaut, auch das ist etwas wert!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2009/02/einstieg-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Concrete5 Theme erstellen</title>
		<link>http://www.codeblog.ch/de/2009/01/concrete5-theme-erstellen/</link>
		<comments>http://www.codeblog.ch/de/2009/01/concrete5-theme-erstellen/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 09:09:51 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=124</guid>
		<description><![CDATA[Die eigene Seite mit dem eigenen Layout &#8211; man will ja schliesslich nichts von der Stange! Dieses Tutorial soll aufzeigen wie man ein Layout in Concrete5 umsetzen kann. Ein Verständnis für HTML und CSS ist sicherlich angebracht. PHP Kenntnisse sind keine erforderlich, ich werde die wenigen Zeilen PHP Code ausführlich beschreiben! Ein Layout solltet ihr [...]]]></description>
			<content:encoded><![CDATA[<p>Die eigene Seite mit dem eigenen Layout &#8211; man will ja schliesslich nichts von der Stange!<br />
Dieses Tutorial soll aufzeigen wie man ein Layout in Concrete5 umsetzen kann.</p>
<p>Ein Verständnis für HTML und CSS ist sicherlich angebracht. PHP Kenntnisse sind keine erforderlich, ich werde die wenigen Zeilen PHP Code ausführlich beschreiben!</p>
<p>Ein Layout solltet ihr schon haben, wenn möglich als HTML und CSS Datei. Ich beschreibe hier nicht wie man aus einer Photoshop Datei in HTML, CSS umwandeln kann.</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/01/layout-concrete5.jpg"><img src="http://www.codeblog.ch/wp-content/uploads/2009/01/layout-concrete5-475x325.jpg" alt="" title="layout-concrete5" width="475" height="325" class="alignnone size-medium wp-image-127" /></a></p>
<p><span id="more-124"></span></p>
<p><strong>Teile des Themes</strong></p>
<p>Als erstes wollen wir einen Überblick über die Bestandteile eines Themes gewinnen:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2009/01/theme-elemente.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/01/theme-elemente.png" alt="" title="theme-elemente" width="351" height="282" class="alignnone size-medium wp-image-129" /></a></p>
<ul>
<li><strong>elements </strong>- Dieser Ordner enthält die Elemente für den Kopf (header) und die Fusszeile (footer)</li>
<li><strong>images </strong>- Ein Theme enthält oft auch Bilder, Hintergrundbilder welche ein Bestandteil des Themes sind zum Beispiel</li>
<li><strong>default.php</strong> &#8211; dies ist die Standarddatei welche für das Layout einer Seite verantwortlich ist</li>
<li><strong>description.txt</strong> &#8211; diese Datei enthält den Namen und eine kurze Beschreibung des Themes, rein informativ</li>
<li><strong>full.php</strong> &#8211; Wie default.php, allerdings wird dieses Layout nur für Seiten vom Typ &#8220;full&#8221; verwendet</li>
<li><strong>home.php</strong> &#8211; Ebenfalls wie default.php, allerdings für Seiten von Typ &#8220;home&#8221;</li>
<li><strong>main.css</strong> &#8211; Hier platzieren wir unsere CSS Anweisungen</li>
<li><strong>thumbnail.png</strong> &#8211; Ein Icon der Grösse 120&#215;90 Pixel dass das Theme zeigt</li>
<li><strong>typography.css</strong> &#8211; ein zweites CSS welches vom HTML Editor verwendet wird</li>
<li><strong>view.php </strong>- das Template das für &#8220;Single Pages&#8221; verwendet wird</li>
</ul>
<p>Sämtliche Files sind in einem eigenen Ordner zu verwalten. Dadurch können Themes später sehr einfach kopiert werden &#8211; Ordner kopieren und im Dashboard aktivieren &#8211; fertig!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2009/01/concrete5-theme-erstellen/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>Link Klicks zählen</title>
		<link>http://www.codeblog.ch/de/2008/04/link-klicks-zahlen/</link>
		<comments>http://www.codeblog.ch/de/2008/04/link-klicks-zahlen/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 08:36:38 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=17</guid>
		<description><![CDATA[Dies ist eine ganz banale Aufgabe, aber mir ist eine Unschönheit aufgefallen bei vielen Scripts die ich gefunden haben, deswegen ein ganz kleiner Artikel zu diesem Thema. Die Aufgabe ist relativ einfach &#8211; wir wollen die Anzahl Klicks auf einem Link zählen. Dazu gibt es viele Varianten und meistens sind die auch sinnvoller als meine.. [...]]]></description>
			<content:encoded><![CDATA[<p>Dies ist eine ganz banale Aufgabe, aber mir ist eine Unschönheit aufgefallen bei vielen Scripts die ich gefunden haben, deswegen ein ganz kleiner Artikel zu diesem Thema.</p>
<p>Die Aufgabe ist relativ einfach &#8211; wir wollen die Anzahl Klicks auf einem Link zählen. Dazu gibt es viele Varianten und meistens sind die auch sinnvoller als meine..</p>
<p><span id="more-17"></span></p>
<p>Zahlreiche Scripts die ich gefunden haben, manipulieren die Adresse die aufgerufen wird:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;http://localhost/linkcounter.php?link=http://www.link.com&quot;&gt;</pre></div></div>

<p>(Der Wert von link müsste noch entsprechend &#8220;angepasst&#8221; werden so dass alle Zeichen korrekt übergeben werden &#8211; php: urlencode, asp: Server.URLEncode usw.)</p>
<p>Nun hat dies zur Folge, dass in der Statuszeile eine unschöne Adresse steht. Wie löst man dies? Per JavaScript die Statuszeile anpassen &#8211; falsch! Früher hat die ganz gut funktioniert, inzwischen ist diese Funktion aber oft deaktiviert. <a href="http://de.selfhtml.org/javascript/objekte/window.htm#status">http://de.selfhtml.org/javascript/objekte/window.htm#status</a></p>
<p><strong>Wie es besser gemacht wird</strong></p>
<p>Wir belassen den Wert in &#8220;href&#8221; so wie er ist. Jedoch erweitern wir den link um einen kleinen JavaScript aufruf</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;http://www.codeblog.ch&quot; onmousedown=&quot;clickCounter(this)&quot;&gt;super blog&lt;/a&gt;</pre></div></div>

<p>Dann noch ein kleines JavaScript in den Header einfügen:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;JavaScript&quot;</span> <span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> clickCounter<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   obj.<span style="color: #660066;">href</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://localhost/linkcounter.php?link=&quot;</span> <span style="color: #339933;">+</span> escape<span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">href</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Dadurch wird die Zieladresse dynamisch bei jedem Klick verändert &#8211; google macht dies übrigens auch so, die Idee ist also alles andere als neu..</p>
<p>Vollständigkeitshalber hier noch ein simples PHP Script das die Links zählt. Für einen praktischen Einsatz aber wohl etwas zu einfach.</p>
<p>Ich habe als DB MySQL verwendet da dies einfach und schnell einzurichten ist. Tabelle &#8220;linkcounter&#8221; mit zwei Spalten erstellen (link,hits). Wichtig ist hier, dass &#8220;link&#8221; eindeutig ist (Primary Key).</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> linkcounter <span style="color: #66cc66;">&#40;</span>link <span style="color: #993333; font-weight: bold;">VARCHAR</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> hits <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span>link<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Dann im PHP Script die Zugangsdaten anpassen und fertig!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// we must have an item &quot;link&quot; in the url</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'link'</span><span style="color: #339933;">,</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// connect to database</span>
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'server'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'user'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'database'</span><span style="color: #339933;">,</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// build query</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'INSERT INTO linkcounter (link,hits) VALUES (\'%s\',1) ON DUPLICATE KEY UPDATE hits=hits+1;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// execute query and close db connection</span>
<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// redirect</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'location: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Zum Schluss sei noch ein kleiner Trick erwähnt. Das Insert Query hat eine kleine Erweiterung &#8220;ON DUPLICATE KEY&#8221;. Dies ist eine MySQL spezifische Anweisung die für diese Anwendung sehr nützlich ist. Dadurch müssen wir kein zweites Query absetzen für den Fall dass der Link bereits in der Datenbank steht. Es gibt schliesslich zwei Operationen: Neue Links einfügen (dies soll ja automatisch geschehen) und den Hit-Counter erhöhen.</p>
<p>Dank MySQL können wir dies mit einem Query tun!<br />
<a href="http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html">http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2008/04/link-klicks-zahlen/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

