﻿<?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>ibonette.com &#187; framework</title>
	<atom:link href="http://www.ibonette.com/tag/framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ibonette.com</link>
	<description>Samimi olmayi vaat edebilirim ama tarafsiz olmayi asla...</description>
	<lastBuildDate>Thu, 09 Sep 2010 14:12:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CakePHP 1.2 Manual for Print out</title>
		<link>http://www.ibonette.com/cakephp-1-2-manual-for-print-out/</link>
		<comments>http://www.ibonette.com/cakephp-1-2-manual-for-print-out/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 18:52:05 +0000</pubDate>
		<dc:creator>ibrahim</dc:creator>
				<category><![CDATA[HAVADAN SUDAN]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[cakephp_1.2_manual.pdf]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.ibonette.com/?p=564</guid>
		<description><![CDATA[As you know, Online Cakephp book  is the best reference book about cake.

I compiled the pdf version of this online book. You can print and use as a desktop reference...

Click here to get the book...

Note that most updated book is online version.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Bildiğiniz gibi, ulaşabileceğiniz en iyi cakephp kitabı şuradaki online kitaptır.

Bir süre önce bu kitabın yazıcı çıktısını almak için pdf  haline getirmiştim. İsteyen arkadaşlar aşağıdaki linkten kitabı indirip bastırabilir.

Tıklayın....

En güncel halinin online versiyon olduğunu unutmayın.]]></description>
			<content:encoded><![CDATA[<p>As you know, <a href="http://book.cakephp.org/" target="_blank">Online Cakephp book</a> is the best reference book about cake.</p>
<p>I compiled the pdf version of this online book. You can print and use as a desktop reference&#8230;</p>
<p><a href="http://ibonette.com/dosyalar/Cakephp_1.2_manual.pdf" target="_blank">Click here to get the book</a>&#8230;</p>
<p><em>Note that most updated book is online version.</em></p>
<p>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p>
<p>Bildiğiniz gibi, ulaşabileceğiniz en iyi cakephp kitabı <a href="http://book.cakephp.org/" target="_blank">şuradaki </a>online kitaptır.</p>
<p>Bir süre önce bu kitabın yazıcı çıktısını almak için pdf  haline getirmiştim. İsteyen arkadaşlar aşağıdaki linkten kitabı indirip bastırabilir.</p>
<p><a href="http://ibonette.com/dosyalar/Cakephp_1.2_manual.pdf">Tıklayın</a>&#8230;.</p>
<p>En güncel halinin online versiyon olduğunu unutmayın.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ibonette.com/cakephp-1-2-manual-for-print-out/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CakePHP Başlangıç: Kurulum ve İlk Uygulama</title>
		<link>http://www.ibonette.com/cakephp-baslangic-kurulum-ve-ilk-uygulama/</link>
		<comments>http://www.ibonette.com/cakephp-baslangic-kurulum-ve-ilk-uygulama/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 01:37:44 +0000</pubDate>
		<dc:creator>ibrahim</dc:creator>
				<category><![CDATA[PRATİK BİLGİLER]]></category>
		<category><![CDATA[PROGRAMLAMA]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[cakephp başlangıç]]></category>
		<category><![CDATA[cakephp kurulum]]></category>
		<category><![CDATA[cakephp örnek uygulama]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php framework]]></category>

		<guid isPermaLink="false">http://www.ibonette.com/?p=251</guid>
		<description><![CDATA[Performans konusunda en kötü php frameworklerinden birisi şu an itibariyle cakephp olduğu için bu frameworkü tercih etmiyorum. (Örneğin şu makaleden benchmark karşılaştırmalarından birisini bulabilirsiniz) Ancak arama motorlarından "cakephp" anahtar kelimesi ile hatırı sayılır bir ziyaretçi kitlesi geldiği için cakephp ye başlangıç yapmak isteyen sevgili dostlarıma yardımcı olacak bir makale yazmayı uygun buldum.

Evet performans konusunda gerçekten kötü olmasına rağmen hiç mi güzel tarafı yok bu frameworkün? Performans kayıplarına rağmen neden insanlar bu frameworkü tercih ediyor?

Bu soruların en önceli cevabı, cakephp 'nin sunduğu otomatikleşmiş araçlarda yatıyor. Framework'ün sunduğu araçlar sayesinde programcının yapması gereken bir çok şeyi cakephp kendisi otomatik olarak yapıyor. Tabii ki bunu yapabilmek için cakephp nin koyduğu kurallara uymak gerekiyor. Veritabanı tasarımı vs gibi konularda bazı konularda kod yazım kurallarına uymak gerekiyor. Bu durum cakephp camiası tarafından "Less Configuration, More Convention" (daha az konfigürasyon, daha çok geliştirme kuralı)  şeklinde ifade ediliyor...]]></description>
			<content:encoded><![CDATA[<p>Performans konusunda en kötü php frameworklerinden birisi şu an itibariyle cakephp olduğu için bu frameworkü tercih etmiyorum. (Örneğin <a href="http://www.avnetlabs.com/php/php-framework-comparison-benchmarks" target="_blank">şu makaleden</a> benchmark karşılaştırmalarından birisini bulabilirsiniz) Ancak arama motorlarından &#8220;cakephp&#8221; anahtar kelimesi ile hatırı sayılır bir ziyaretçi kitlesi geldiği için cakephp ye başlangıç yapmak isteyen sevgili dostlarıma yardımcı olacak bir makale yazmayı uygun buldum.</p>
<p>Evet performans konusunda gerçekten kötü olmasına rağmen hiç mi güzel tarafı yok bu frameworkün? Performans kayıplarına rağmen neden insanlar bu frameworkü tercih ediyor?</p>
<p>Bu soruların en önceli cevabı, cakephp &#8216;nin sunduğu otomatikleşmiş araçlarda yatıyor. Framework&#8217;ün sunduğu araçlar sayesinde programcının yapması gereken bir çok şeyi cakephp kendisi otomatik olarak yapıyor. Tabii ki bunu yapabilmek için cakephp nin koyduğu kurallara uymak gerekiyor. Veritabanı tasarımı vs gibi konularda bazı konularda kod yazım kurallarına uymak gerekiyor. Bu durum cakephp camiası tarafından &#8220;Less Configuration, More Convention&#8221; (daha az konfigürasyon, daha çok geliştirme kuralı)  şeklinde ifade ediliyor.  Bunun ne demek olduğunu aşağıda göreceksiniz.</p>
<p>Diğer çoğu php framework gibi cakephp de MVC (Model, View, Controller) yaklaşımı ile oluşturulmuştur. Hatta Bu yaklaşıma en katı şekilde bağlı olan ve programcıyı MVC dışına çıkmamak için en çok zorlayan frameworklerden birisi cakephp&#8217;dir.</p>
<p>Yazımın devam eden kısımlarına geçmeden önce  <a href="http://www.ibonette.com/codeigniter-1-baslangic/" target="_blank">şuradaki</a> yazımdaki MVC konusundaki açıklamaları okumanız çok iyi olur. Ayrıca bu yazıda okuyucuların, &#8220;php&#8221;, &#8220;php ile nesne tabanlı programlama&#8221;, &#8220;mvc yaklaşımı&#8221; hakkında bilgi sahibi olunduğu varsayıyorum. Bu konularda eksiğiniz olduğunu düşünüyorsanız lütfen ilgili konuları araştırınız.</p>
<p><span style="text-decoration: underline;"><strong>CakePHP Nasıl Çalışır?</strong></span></p>
<p>MVC yaklaşımını kullanan cakephp &#8216;de, uygulamadaki veri akışı şu şekilde olur;</p>
<p><a href="http://www.ibonette.com/wp-content/uploads/2009/01/cakephp-nasil-calisir.jpg"><img class="alignleft size-full wp-image-252" title="cakephp-nasil-calisir" src="http://www.ibonette.com/wp-content/uploads/2009/01/cakephp-nasil-calisir.jpg" alt="" width="314" height="164" /></a></p>
<p>1.İstek, kullanıcı verisi (get ve post verisi) aracılığı ile controllera iletilir.<br />
2.Controller, isteği işler ve veritabanına erişmek için modele iletir.<br />
3.Model, controller isteklerine, sonuç verisini göndererek ya da gönderilen verileri veritabanına ekleyerek karşılık verir.<br />
4.Controller, modelden aldığı bu yanıtları, kullanıcıya göstermek amacıyla viewa gönderir.<br />
5.Vİew, aldığı yanıtları belirlenen formatta kullanıcıya gösterir.</p>
<p><span style="text-decoration: underline;"><strong>Less Configuration, More Convention (daha az konfigürasyon, daha çok geliştirme kuralı)</strong></span></p>
<p>Bu kavram, konfigürasyondan çok, işi yaparken belli kurallara uymak anlamına gelir.</p>
<p>CakePHP ile çalışmaya başlamak için veritabanı adından başka bir konfigürasyon zorunluluğu yoktur. Bunun yerine &#8220;convention&#8221; denilen bir nevi &#8220;geliştirme kuralları&#8221; ya da &#8220;isimlendirme kuralları&#8221; denebilecek şartlar vardır. Örneğin: veritabanındaki alan isimleri, model-controller-view  isimleri ve yerleri&#8230;  Bunlar cakephp kurallarına göre isimlendirilip  yerleştirilirse cake onları otomatik olarak bulur. Bu nedenle cakephp convetions konusunu iyi bilmek ve uygulamak gerekir. Bunu anlayıp uygulamaya alıştıktan sonra konfigürasyon konusuna vakit ayırmadan uygulama geliştirebilirsiniz.</p>
<p><span style="text-decoration: underline;"><strong>Otomatik Kod Üretimi</strong></span></p>
<p>&#8220;Baking script&#8221;  olarak da bilinen cake bileşeni sayesinde, veritabanı tablolarını tanımlayarak cake in otomatik kod üretimi özelliğinden faydalanılabilinir. Bu sayede ihtiyacımız olan model, controller ve view ler otomatik olarak oluşturulur. Bu üretilen kodlar bize, veritabanı tablolarımız üzerinde crud (ekleme, okuma, düzeltme, silme) işlemleri yapabileceğimiz uygulamayı sağlar.</p>
<p><span style="text-decoration: underline;"><strong>Veritabanı ile Hızlı Çalışma</strong></span></p>
<p>&#8220;Cake database abstraction&#8221; sayesinde karmaşık sql sorguları ile uğraşmadan veritabanı üzerinde işlem yapabiliriz. Bu sayede sadece bir tablodan veri çekmenin yanısıra, ilişkili tablolalardaki verilerin hepsini yada bir kısmını aynı anda çekme şansımız olur. Örneğin &#8220;post&#8221; tablosunda gönderilen blog postlarını ve comments tablosunuda ilgili blog postuna yapılan yorumları tuttuğunu farzedelim. Bu durumda bir postla birlikte ilgili yorumları da çekmek istersek, post tablosundan bilgiyi dondüren tek bir model metodunu çağırmamız yeterlidir. Cake ilişkili diğer tablolardan (comments) da ilişkili  verileri getirecektir. Diğer tablolardan da ilişkili verileri almak için karmaşık sql sorguları yazmamıza gerek yoktur.</p>
<p><span style="text-decoration: underline;"><strong>Kurulum</strong></span></p>
<p>Kurulum için gereksinimler;</p>
<p>- Apache kurulu ve çalışıyor olmalı<br />
- Mysql kurulu ve çalışıyor olmalı<br />
- Php 4.3.2 ve üzeri kurulu ve çalışıyor olmalı<br />
- <a href="http://cakephp.org/downloads" target="_blank">Cakephp son versiyonu</a> kurulu ve çalışıyor olmalı<br />
- mod_rewrite açık olmalı  (httpd.conf )<br />
- AllowOverride izni verilmiş olmalı     (httpd.conf )</p>
<p>Öncelikle <a href="http://cakephp.org/downloads" target="_blank">cakephp&#8217;nin resmi sitesinden en son sürümünü</a> indirerek sıkıştırılmış dosyayı açarak sunucuya atıyoruz. Daha sonra cakephp&#8217;yi attığımız yerin url&#8217;sini tarayıcımıza yazarak frameworkü çalıştırıyoruz.</p>
<p>Sunucuda &#8220;mod_rewrite&#8221; açık (enabled) olmalı.  Eğer aşağıdaki birinci görüntü geliyorsa çalışmaya hazırsınız. İkinci görüntüyü alıyorsanız. Apache mod_rewrite açık değil demektir. Bunun için apache httpd.conf dosyasındaki #LoadModule rewrite_module modules/mod_rewrite.so satırının başındaki # kaldırılarak sunucu tekrar başlatılarak ilgili modülün yüklenmesi sağlanır. (Eğer bir hosting kullanıyorusanız, muhtemelen httpd.conf dosyasına erişim hakkınız olmayacaktır. bu takdirde hosting firmanızla görüşerek konuyu halletmeniz gerekiyor.)</p>
<p><a href="http://www.ibonette.com/wp-content/uploads/2009/01/ilk-ekran-sorun-yok.jpg"><img class="alignleft size-medium wp-image-253" title="ilk-ekran-sorun-yok" src="http://www.ibonette.com/wp-content/uploads/2009/01/ilk-ekran-sorun-yok.jpg" alt="" width="299" height="232" /></a></p>
<p><a href="http://www.ibonette.com/wp-content/uploads/2009/01/ilk-ekran-sorun-var.jpg"><img class="alignright size-full wp-image-254" title="ilk-ekran-sorun-var" src="http://www.ibonette.com/wp-content/uploads/2009/01/ilk-ekran-sorun-var.jpg" alt="" width="315" height="224" /></a></p>
<p><span style="text-decoration: underline;"><strong><br />
</strong></span></p>
<p><span style="text-decoration: underline;"><strong>Örnek Uygulama</strong></span></p>
<p>Veritabanımız;</p>
<p><em>CREATE TABLE tasks (<br />
id int(10) unsigned NOT NULL auto_increment,<br />
title varchar(255) NOT NULL,<br />
done tinyint(1) default NULL,<br />
created datetime default NULL,<br />
modified datetime default NULL,<br />
PRIMARY KEY (id)<br />
);</em></p>
<p>[Convention] :Cakephp conventionları gereği veritabanındaki tablo isimleri (ingilizceki) çoğul olmalı ve her tablo, id isimli bir birincil anahtara (primary key) sahip olmalıdır</p>
<p><code><span style="color: #000000;"> </span></code><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!--[if gte mso 10]><br />
<mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Normal Tablo"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0cm 5.4pt 0cm 5.4pt; 	mso-para-margin:0cm; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --></p>
<p>/app/config içindeki database.php.default dosyasını database.php olarak değiştirip aşağıdaki ayaları dosya içinden yapıyoruz;</p>
<p><!--[endif]--><code><strong><span style="font-size: 10pt; color: #007700;">var </span><span style="font-size: 10pt; color: #0000bb;">$default </span><span style="font-size: 10pt; color: #007700;">= array( </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
</span><code><span style="font-size: 10pt; color: #dd0000;">'driver' </span><span style="font-size: 10pt; color: #007700;">=&gt; </span><span style="font-size: 10pt; color: #dd0000;">'mysql'</span><span style="font-size: 10pt; color: #007700;">, </span></code><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
</span><code><span style="font-size: 10pt; color: #dd0000;">'persistent' </span><span style="font-size: 10pt; color: #007700;">=&gt; </span><span style="font-size: 10pt; color: #0000bb;">false</span><span style="font-size: 10pt; color: #007700;">, </span></code><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
</span><code><span style="font-size: 10pt; color: #dd0000;">'host' </span><span style="font-size: 10pt; color: #007700;">=&gt; </span><span style="font-size: 10pt; color: #dd0000;">'localhost'</span><span style="font-size: 10pt; color: #007700;">, </span></code><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
</span><code><span style="font-size: 10pt; color: #dd0000;">'login' </span><span style="font-size: 10pt; color: #007700;">=&gt; </span><span style="font-size: 10pt; color: #dd0000;">'root'</span><span style="font-size: 10pt; color: #007700;">, </span></code><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
</span><code><span style="font-size: 10pt; color: #dd0000;">'password' </span><span style="font-size: 10pt; color: #007700;">=&gt; </span><span style="font-size: 10pt; color: #dd0000;">''</span><span style="font-size: 10pt; color: #007700;">, </span></code><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
</span><code><span style="font-size: 10pt; color: #dd0000;">'database' </span><span style="font-size: 10pt; color: #007700;">=&gt; </span><span style="font-size: 10pt; color: #dd0000;">'caketoodoo'</span><span style="font-size: 10pt; color: #007700;">, </span></code><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
</span><code><span style="font-size: 10pt; color: #dd0000;">'prefix' </span><span style="font-size: 10pt; color: #007700;">=&gt; </span><span style="font-size: 10pt; color: #dd0000;">''</span><span style="font-size: 10pt; color: #007700;">, </span></code><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
<code>); </code></span></strong><code><span style="color: #000000;"><span style="color: #007700;"><br />
</span></span></code></p>
<p>Sonrasında tarayıcımızda aşağıdaki ekranı almamız gerekir;</p>
<p><a href="http://www.ibonette.com/wp-content/uploads/2009/01/veritabani-gosteriyoruz.jpg"><img class="alignnone size-full wp-image-255" title="veritabani-gosteriyoruz" src="http://www.ibonette.com/wp-content/uploads/2009/01/veritabani-gosteriyoruz.jpg" alt="" width="229" height="209" /></a></p>
<p>Uygulamamızın buraya kadarki kısmında cakephp&#8217;ye, veritabanımızı göstermiş olduk.</p>
<p><span style="text-decoration: underline;">Model</span></p>
<p>Uygulamamızda tek bir tablo olduğu için, sadece bir adet model oluşturacağız.</p>
<p>/app/models  dizini içinde task.php isimli dosya oluşturup aşağıdaki kodları içine ekliyoruz;</p>
<p class="MsoNormal"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!--[if gte mso 10]><br />
<mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Normal Tablo"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0cm 5.4pt 0cm 5.4pt; 	mso-para-margin:0cm; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --></p>
<p><!--[endif]--></p>
<p class="MsoNormal"><code><strong><span style="font-size: 10pt; color: #0000bb;">&lt;?php </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000bb;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #007700;">class </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">Task </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">extends </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">AppModel </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">{ </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
<code> var </code></span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">$name </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">= </span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'Task'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
<code>} </code><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">?&gt;</span></strong></code></p>
<p><code><strong></strong></code></p>
<p>[Convention] Burada &lt;?php  den önce ve ?&gt; den sonra herhangi bir boşluk tab vb olmadığından emin olunması gerekiyor.</p>
<p>[Convention] Model dosya adı temsil ettiği tablonun (ingilizce çoğul olan adının) tekil halidir. Yani veritabanı tablo adı tasks ise model dosya  adı task.php olur.</p>
<p>[Convention]  Model class adı, temsil ettiği tablonun (ingilizce çoğul olan adının) tekil halidir. Ayrıca ilk harfler büyüktür. . Yani veritabanı tablo adı tasks ise model class adı Task olur.</p>
<p>Model classı frameworkün  AppModel  classından extend edilir. Ayrıca AppModel classı da temel model classı olan Model den extend edilmiştir. Model isimli bu temel class, veritabanı ile ilgili crud işleri ile ilgili metodları barındırır.</p>
<p><span style="text-decoration: underline;">Controller</span></p>
<p>/app/controllers  içinde   tasks_controller.php isimli dosya oluşturup, aşağıdaki kodları yerleştiriyoruz;<br />
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0cm; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} code 	{font-family:"Courier New"; 	mso-ascii-font-family:"Courier New"; 	mso-fareast-font-family:"Times New Roman"; 	mso-hansi-font-family:"Courier New"; 	mso-bidi-font-family:"Courier New";} @page Section1 	{size:595.3pt 841.9pt; 	margin:70.85pt 70.85pt 70.85pt 70.85pt; 	mso-header-margin:35.4pt; 	mso-footer-margin:35.4pt; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --><!--[if gte mso 10]> <mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Normal Tablo"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0cm 5.4pt 0cm 5.4pt; 	mso-para-margin:0cm; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --> <!--[endif]--></p>
<p class="MsoNormal"><code><strong><span style="font-size: 10pt; color: #0000bb;">&lt;?php </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000bb;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #007700;">class </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">TasksController </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">extends </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">AppController </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">{ </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
<code> var </code></span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">$name </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">= </span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'Tasks'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
<code> function </code></span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">index</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">() { </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
<code> </code></span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">$this</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">-&gt;</span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">set</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">(</span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'tasks'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">, </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">$this</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">-&gt;</span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">Task</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">-&gt;</span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">find</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">(</span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'all'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">)); </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
<code> } </code><br />
<code>} </code><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">?&gt;</span></strong></code></p>
<p>[Convention] Burada  da &lt;?php  den önce ve ?&gt; den sonra herhangi bir boşluk tab vb olmadığından enim olunması gerekiyor.Bu örnekte bir modele bir controller karşılık geliyor ancak böyle olması, her modele bir controller karşılık gelemesi zorunlu değildir.</p>
<p>[Convention] Controller dosya ismi, veritabanındaki tablo adına aynen çoğul haliyle _controller.php  eklenerek belirlenir. Yani uygulamamızda  tablo adı tasks olduğu için controller adı tasks_controller.php olacaktır.</p>
<p>[Convention] Model class isimlerinde olduğu gibi controlller class isimlerinde de kelimelerin ilk harfleri büyük olur. Örneğimizde: tasks_controller.php isimli controller ın class ismi TasksController olacaktır.</p>
<p><span style="text-decoration: underline;"><strong>Veritabanındaki Bütün Kayıtların Gösterilmesi</strong></span></p>
<p>tasks_controller.php dosyası içinde, TasksController sınıfımıza, index isimli metodu aşağıdaki gibi ekleyelim. Controller içindekianonim fonksiyonlar (public functions) &#8220;action&#8221; olarak adlandırılır.  tasks_controller.php dosyanız şu şekilde görünecektir;</p>
<p><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!--[if gte mso 10]><br />
<mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Normal Tablo"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0cm 5.4pt 0cm 5.4pt; 	mso-para-margin:0cm; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --></p>
<p><!--[endif]--></p>
<p class="MsoNormal"><code><strong><span style="font-size: 10pt; color: #0000bb;">&lt;?php </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000bb;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #007700;">class </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">TasksController </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">extends </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">AppController </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">{ </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
<code> var </code></span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">$name </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">= </span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'Tasks'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
<code> function </code></span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">index</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">() { </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
<code> </code></span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">$this</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">-&gt;</span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">set</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">(</span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'tasks'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">, </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">$this</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">-&gt;</span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">Task</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">-&gt;</span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">find</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">(</span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'all'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">)); </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
<code> } </code><br />
<code>} </code><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">?&gt;</span></strong></code></p>
<p>/app/views dizini içinde &#8220;tasks&#8221; isimli bir dizin oluşturuyoruz.</p>
<p>task dizini içinde index.ctp isimli bir dosya oluşturup aşağıdaki kodları kopyalıyoruz;</p>
<p><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!--[if gte mso 10]><br />
<mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Normal Tablo"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0cm 5.4pt 0cm 5.4pt; 	mso-para-margin:0cm; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --></p>
<p><!--[endif]--></p>
<p class="MsoNormal"><code><strong><span style="font-size: 10pt; color: black;">&lt;h2&gt;Tasks&lt;/h2&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">&lt;?php </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">if(empty(</span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">$tasks</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">)): </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">?&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000bb;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: black;">There are no tasks in this list </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">&lt;?php </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">else: </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">?&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000bb;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: black;">&lt;table&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"><br />
<code>&lt;tr&gt; </code><br />
<code>&lt;th&gt;Title&lt;/th&gt; </code><br />
<code>&lt;th&gt;Status&lt;/th&gt; </code><br />
<code>&lt;th&gt;Created&lt;/th&gt; </code><br />
<code>&lt;th&gt;Modified&lt;/th&gt; </code><br />
<code>&lt;th&gt;Actions&lt;/th&gt; </code><br />
<code>&lt;/tr&gt; </code><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">&lt;?php </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">foreach (</span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">$tasks </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">as </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">$task</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">): </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">?&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000bb;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: black;">&lt;tr&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"><br />
<code>&lt;td&gt; </code><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">&lt;?php </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">echo </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">$task</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">[</span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'Task'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">][</span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'title'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">] </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">?&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000bb;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: black;">&lt;/td&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"><br />
<code>&lt;td&gt; </code><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">&lt;?php </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000bb;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #007700;">if(</span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">$task</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">[</span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'Task'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">][</span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'done'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">]) echo </span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">"Done"</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
<code>else echo </code></span></strong><code><strong><span style="font-size: 10pt; color: #dd0000;">"Pending"</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #007700;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">?&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000bb;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: black;">&lt;/td&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"><br />
<code>&lt;td&gt; </code><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">&lt;?php </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">echo </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">$task</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">[</span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'Task'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">][</span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'created'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">] </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">?&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000bb;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: black;">&lt;/td&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"><br />
<code>&lt;td&gt; </code><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">&lt;?php </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">echo </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">$task</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">[</span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'Task'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">][</span></strong></code><code><strong><span style="font-size: 10pt; color: #dd0000;">'modified'</span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">] </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">?&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000bb;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: black;">&lt;/td&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"><br />
<code>&lt;td&gt; </code><br />
<code>&lt;!-- actions on tasks will be added later --&gt; </code><br />
<code>&lt;/td&gt; </code><br />
<code>&lt;/tr&gt; </code><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">&lt;?php </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">endforeach; </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">?&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000bb;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: black;">&lt;/table&gt; </span></strong></code><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"><br />
</span></strong><code><strong><span style="font-size: 10pt; color: #0000bb;">&lt;?php </span></strong></code><code><strong><span style="font-size: 10pt; color: #007700;">endif; </span></strong></code><code><strong><span style="font-size: 10pt; color: #0000bb;">?&gt;</span></strong></code></p>
<p>Tarayıcınız aracılığı ile &#8230;/tasks/index linkini çalıştırın.  Aşağıdakine benzer şekilde veritabanımızda herhangi bir kayıt olmadığını gösteren çıktı alacaksınız;</p>
<p><a href="http://www.ibonette.com/wp-content/uploads/2009/01/tum-kayitlar.jpg"><img class="alignleft size-full wp-image-256" title="tum-kayitlar" src="http://www.ibonette.com/wp-content/uploads/2009/01/tum-kayitlar.jpg" alt="" width="500" height="315" /></a></p>
<p>Eğer veritabanımızda kayıt olsaydı burada tüm kayıtları görecektik.</p>
<p>Bu uygulama ile temel olarak cakephp çalışma mantığını, tipik bir uygulamanın nasıl olduğunu anlatmaya çalıştım. İleriki yazılarımda bu uygulamamıza yeni kayıt ekleme, değişiklik, silme gibi temel özellikleri nasıl ekleyeceğimizi anlatmaya çalışacağım.</p>
<p>Sevgiler</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ibonette.com/cakephp-baslangic-kurulum-ve-ilk-uygulama/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>CodeIgniter -2: Controller</title>
		<link>http://www.ibonette.com/codeigniter-2-controller/</link>
		<comments>http://www.ibonette.com/codeigniter-2-controller/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 13:03:04 +0000</pubDate>
		<dc:creator>ibrahim</dc:creator>
				<category><![CDATA[PROGRAMLAMA]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[codeigniter controller]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[Controllerları Alt Klasörlerde Organize Etmek]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[Medotlar (Fonksiyonlar)]]></category>
		<category><![CDATA[Metod Parametresini url İle Geçirmek]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php framework]]></category>
		<category><![CDATA[Sınıf Yapılandırıcıları (Class Constructors)]]></category>
		<category><![CDATA[Varsayılan Controller Tanımlama]]></category>

		<guid isPermaLink="false">http://www.ibonette.com/?p=93</guid>
		<description><![CDATA[Bir önceki yazımda CodeIgniter ' a başlangıç yapmıştık. Şimdi konuyu biraz daha ilerletip CodeIgniter çalışma yapısını anlamak için öncelikle kavramamız  gereken MVC 'nin ilk ayağına, yani controller kavramına değineceğiz.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ibonette.com/codeigniter-1-baslangic/" target="_blank">Bir önceki</a> yazımda CodeIgniter &#8216; a başlangıç yapmıştık. Şimdi konuyu biraz daha ilerletip CodeIgniter çalışma yapısını anlamak için öncelikle kavramamız  gereken MVC &#8216;nin ilk ayağına, yani controller kavramına değinerek ilk programımızı yazacağız.</p>
<p>Controller, basit olarak bir link ile çağırılabilen bir class dosyasıdır. Örneğin : aşağıdaki örnekte CI   <em>blog.php</em> isimli controllerı bulup yüklemeye çalışır. Sonuç olarak url deki ilk bölümle aynı isimli class dosyası çalıştırılır. Linkte .php uzantısının kullanılmadığına dikkat edin&#8230;</p>
<p>www.siteadiniz.com/index.php/blog/</p>
<p><strong>Merhaba Dünya</strong></p>
<p>Herhangi bir metin editöründe aşağıdaki kodu yazarak <em>blog.php</em> ismi ile application/controllers/  dizininin içine kaydedelim; (Kod içindeki class ismi büyük harfle başlamalıdır. Küçük harfle başlayamaz. blog olamaz Blog olmalıdır.)</p>
<pre><strong><span><strong><code><span style="color: #000000;"><span style="color: #0000bb;">&lt;?php
</span><span style="color: #007700;">class </span><span style="color: #0000bb;">Blog </span><span style="color: #007700;">extends </span><span style="color: #0000bb;">Controller </span><span style="color: #007700;">{
    function </span><span style="color: #0000bb;">index</span><span style="color: #007700;">()
    {
        echo </span><span style="color: #dd0000;">'Merhaba Dünya!'</span><span style="color: #007700;">;
    }
}
</span><span style="color: #0000bb;">?&gt;</span></span></code></strong></span></strong></pre>
<p>Şimdi aşağıdaki linke girin;<br />
www.siteadiniz.com/index.php/blog/<br />
Doğru yaptıysanız “Merhaba Dünya!”  yazısını göreceksiniz.</p>
<p><strong>Metodlar (Fonksiyonlar)</strong></p>
<p>Bildiğiniz gibi sınıfların en önemli parçalarından birisi metotlardır. Controllerında bir sınıf olduğunu söylemiştik. Aynen url nin ilk parçasında ilgili kontrollerı çalıştırdığımız gibi, metod ve metodların parametrelerini de url ile içerisinden çağırabiliriz.</p>
<p>Yukarıdaki örnekte çalışacak metod ismi index() dir. Url nin ikinci bölümü boş ise index() varsayılan olarak yüklenir.  Yukarıdaki örnekte “Merhaba Dünya!” yazısını görmenin bir diğer yolu ise aşağıdaki linki takip etmektir.</p>
<p>www.siteadiniz.com/index.php/blog/index/</p>
<p><em>Url nin ikinci bölümü, controller ın hangi fonksiyonu çağırdığını belirler.</em></p>
<p>Şimdi yukarıdaki örneği aşağıdaki şekilde değiştirelim; (değişikliği blog.php dosyasında yapacaksınız)</p>
<pre><strong><span><strong><code><span style="color: #000000;"><span style="color: #0000bb;">&lt;?php
</span><span style="color: #007700;">class </span><span style="color: #0000bb;">Blog </span><span style="color: #007700;">extends </span><span style="color: #0000bb;">Controller </span><span style="color: #007700;">{
    function </span><span style="color: #0000bb;">index</span><span style="color: #007700;">()
    {
        echo </span><span style="color: #dd0000;">'</span></span></code></strong></span></strong><strong><span><span><strong><span><strong><code><span style="color: #000000;"><span style="color: #dd0000;">Merhaba Dünya!</span></span></code></strong></span></strong></span></span></strong><strong><span><strong><code><span style="color: #000000;"><span style="color: #dd0000;">'</span><span style="color: #007700;">;
    }
    function </span><span style="color: #0000bb;">comments</span><span style="color: #007700;">()
    {
        echo </span><span style="color: #dd0000;">'Bu da diğer metod'</span><span style="color: #007700;">;
    }
}
</span><span style="color: #0000bb;">?&gt;</span></span></code></strong></span></strong><!--[endif]-->

<span style="font-size: 10pt; font-family: Arial;">Şimdi şu linki çağıralım; (url nin ikinci bölümü ile comment() metodumuzu çalıştırdığımza dikkat edin)</span>
<code><span style="font-size: 10pt; font-family: Arial;">www.siteadiniz.com/index.php/</span></code><var><strong><span style="font-size: 10pt; font-family: Arial;">blog</span></strong></var><code><span style="font-size: 10pt; font-family: Arial;">/</span></code><samp><strong><span style="font-size: 10pt; font-family: Arial;">comments</span></strong></samp><code><span style="font-size: 10pt; font-family: Arial;">/</span></code>
<span style="font-size: 10pt; font-family: Arial;">Şimdi ise tarayıcınızda “Bu da diğer metod”  yazısını göreceksiniz.
<strong>
Metod Parametresini url İle Geçirmek</strong>

Eğer url ikiden fazla bölüm içeriyorsa, 3 ve sonraki bölümler, ilgili metoda parametre olarak aktarılır.
Örneğin aşağıdaki kodu <em>products.php</em> ismi ile application/controllers/  içine kaydedelim.

</span><strong><code><span style="color: #000000;"><span style="color: #0000bb;">&lt;?php
</span><span style="color: #007700;">class </span><span style="color: #0000bb;">Products </span><span style="color: #007700;">extends </span><span style="color: #0000bb;">Controller </span><span style="color: #007700;">{
    function </span><span style="color: #0000bb;">shoes</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$sandals</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$id</span><span style="color: #007700;">)
    {
        echo </span><span style="color: #0000bb;">$sandals</span><span style="color: #007700;">;
        echo </span><span style="color: #0000bb;">$id</span><span style="color: #007700;">;
    }
}
</span><span style="color: #0000bb;">?&gt;
</span></span></code></strong></pre>
<p><!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0cm; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} code 	{font-family:"Courier New"; 	mso-ascii-font-family:"Courier New"; 	mso-fareast-font-family:"Times New Roman"; 	mso-hansi-font-family:"Courier New"; 	mso-bidi-font-family:"Courier New";} kbd 	{font-family:"Courier New"; 	mso-ascii-font-family:"Courier New"; 	mso-fareast-font-family:"Times New Roman"; 	mso-hansi-font-family:"Courier New"; 	mso-bidi-font-family:"Courier New";} samp 	{font-family:"Courier New"; 	mso-ascii-font-family:"Courier New"; 	mso-fareast-font-family:"Times New Roman"; 	mso-hansi-font-family:"Courier New"; 	mso-bidi-font-family:"Courier New";} @page Section1 	{size:612.0pt 792.0pt; 	margin:70.85pt 70.85pt 70.85pt 70.85pt; 	mso-header-margin:35.4pt; 	mso-footer-margin:35.4pt; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --></p>
<p><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Normal Tablo"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0cm 5.4pt 0cm 5.4pt; 	mso-para-margin:0cm; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --> Sonra da aşağıdaki linki çalıştıralım;</p>
<p>www.siteadiniz.com/index.php/products/shoes/<strong>sandals</strong>/<strong>123</strong></p>
<p>Üçüncü ve dördüncü bölümlerdeki bilgiler fonksiyon parametrelerine değer olarak atanır ve bu parametrelere uygun bilgileri sayfaya alır. Yani tarayıcıya &#8220;sandals&#8221; ve &#8220;123&#8243; kelimelerini yazdırır.</p>
<p><strong>Varsayılan Controller Tanımlama</strong></p>
<p>Url bulunamadığında ya da siteye ilk girildiğinde CI ye gitmesi için varsayılan olarak yüklenecek controller tanımlaması yapılabilir.</p>
<p>Default Controller (varsayılan controller) tanımlaması yapmak için application/config/routes.php içindeki aşağıdaki kodla gerekli değişiklik yapılabilir;<br />
<em> $route['default_controller'] = &#8216;Blog&#8217;;</em></p>
<p>Blog, burada varsayılan olarak yüklenecek controller adıdır. Bu ayardan sonra, eğer yukarıdaki örnekte ana index.php dosyanızı herhangi bir url bölümü kullanmadan çalıştırırsanız, “Merhaba Dünya!” yazsını görürsünüz.</p>
<p><strong>Controllerları Alt Klasörlerde Organize Etmek</strong></p>
<p>Bazı durumlarda controller ları alt klasörlere bölmek isteyebilirsiniz. Bunu, <em>application/controllers</em> içinde alt klasörler açarak yapabiliriniz.</p>
<p>Bunu yaptığınız zaman url ’nin ilk bölümünde klasör ismi kullanılmalıdır. Örneğin controller,   “application/controllers/<strong>products</strong>/shoes.php” altında olduğunu varsayarsak url şu şekilde olmalıdır;<br />
www.siteadiniz.com/index.php/<strong>products</strong>/shoes/123</p>
<p>Her bir alt klasör varsayılan controller içerebilir. Alt katagoriye giden bir link bulunamadığında ya da benzer bir durumda varsayılan controller olarak çalışmak üzere ayrı bir varsayılan conroller tanımlanabilir. Bu, application/config/routes.php dosyasından yapılır.</p>
<p><strong>Sınıf Yapılandırıcıları (Class Constructors) </strong></p>
<p>Yapılandırıcılar, sınıftan nesne oluştururken bazı varsayılan değerleri ayarlamak ya da bazı varsayılan işlemleri çalıştırmak için kullanılır. Bildiğiniz gibi yapılandırıcılar, değer döndürmez. Sadece belli varsayılan işleri yapar. Yapılandırıcılar (consructors) hakkında daha fazla bilgi için php5 de nesne tabanlı programlama konusu incelenmelidir.</p>
<p>Cıdeigniter&#8217;da kullanımı şu şekildedir (php5 için);</p>
<pre><strong><code><span style="color: #000000;"><span style="color: #0000bb;">&lt;?php
</span><span style="color: #007700;">class </span><span style="color: #0000bb;">Blog </span><span style="color: #007700;">extends </span><span style="color: #0000bb;">Controller </span><span style="color: #007700;">{
       function </span><span style="color: #0000bb;">__construct</span><span style="color: #007700;">()
       {
            </span><span style="color: #0000bb;">parent</span><span style="color: #007700;">::</span><span style="color: #0000bb;">Controller</span><span style="color: #007700;">();  
       }
}
</span><span style="color: #0000bb;">?&gt;
</span></span></code></strong></pre>
<p>Burada   parent::Controller();  kodunu kullanmak durumundayız çünkü yerel yapılandırıcı, parent controller ‘ı ezeceği için, onu manuel olarak çağırmamız gerekir.</p>
<p>MVC &#8216;nin ve dolayısı ile codeigniter&#8217;in bel kemiği olan controller kavramından genel olarak bu kadar değinmek yeterli olacaktır sanırım. Zaten CI ile uygulama geliştirme sürecimiz çok büyük oranda controller, model ve view dosyaları yazmaktan ibaret olduğu için bu konuyu iyi öğrenmek durumdayız.</p>
<p>Sonraki codeigniter yazılarımda görüşmek üzere, sağlıcakla kalın&#8230;</p>
<p><span style="text-decoration: underline;"><strong>Kaynakça:</strong></span></p>
<p><a href="http://codeigniter.com/user_guide/" target="_blank">CodeIgniter Kullanıcı Klavuzu</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ibonette.com/codeigniter-2-controller/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
