<?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>AquarLife &#187; CakePHP</title>
	<atom:link href="http://www.aquarhead.com/tag/cakephp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aquarhead.com</link>
	<description>天空中的羽翼距离你还有多远 在你隐藏的感情之中寻找我的踪迹</description>
	<lastBuildDate>Wed, 01 Feb 2012 17:08:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/><cloud domain='www.aquarhead.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>CakePHP自学笔记（六）：模型的构建和关联</title>
		<link>http://www.aquarhead.com/2010/03/cakephp-notes-6/</link>
		<comments>http://www.aquarhead.com/2010/03/cakephp-notes-6/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 13:32:50 +0000</pubDate>
		<dc:creator>AquarHEAD</dc:creator>
				<category><![CDATA[Code Fortress]]></category>
		<category><![CDATA[AquarTutorial]]></category>
		<category><![CDATA[Association]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Model]]></category>

		<guid isPermaLink="false">http://www.aquarhead.com/?p=805</guid>
		<description><![CDATA[AquarTutorial 第一期 -CakePHP自学笔记 （一）：利用Ubuntu搭建开发环境 （二）：数据库配置与连接 （三）：MVC开发模式简介 （四）：CakePHP的命名规范 （五）：Cake中的MVC开发 >>（六）：模型的构建和关联]]></description>
			<content:encoded><![CDATA[<p>AquarTutorial 第一期<br />
-CakePHP自学笔记</p>
<p><a href="http://www.aquarhead.com/2010/03/cakephp-notes-1/">（一）：利用Ubuntu搭建开发环境</a><br />
<a href="http://www.aquarhead.com/2010/03/cakephp-notes-2/">（二）：数据库配置与连接</a><br />
<a href="http://www.aquarhead.com/2010/03/cakephp-notes-3/">（三）：MVC开发模式简介</a><br />
<a href="http://www.aquarhead.com/2010/03/cakephp-notes-4/">（四）：CakePHP的命名规范</a><br />
<a href="http://www.aquarhead.com/2010/03/cakephp-notes-5/">（五）：Cake中的MVC开发</a><br />
>>（六）：模型的构建和关联 </p>
<p><-<-<-<-<-<-<-<-<-<-<-<-<-</p>
<h3>“重构”的代价</h3>
<p>直到想起来有<a href="http://book.cakephp.org/view/78/Associations-Linking-Models-Together">这玩意</a>才发现自己有多笨。。。所以郁闷了好几天没看，alpha版本里面也没有用到模型的关联，今天实在无聊的要命，就读了一下，然后改了DarkBook的代码，重新组织了数据的结构，麻烦不说，我还是搞不明白为什么都声明了'foreignKey' => 'owner'了，Cake还是返回没有User模型没有id的错误。God Damn It！！看来Cake习惯了每个模型都有个id当主键。>_<||。。。</p>
<p>所以刚才从数据库改起，模型、控制器、视图全有改动，幸亏DarkBook只有两个控制器，要不我肯定疯掉了——这就是不读完教程就乱写的后果。。。</p>
<h3>四种关联</h3>
<p>CakePHP提供了四种类型的关联：hasOne、hasMany、belongsTo和hasAndBelongsToMany。四者分别对应模型中一个同名的变量。</p>
<p>声明了模型之间的关联之后，我们（在一般情况下）就不需要在控制器中引入$uses变量来接收其他模型的数据了。比如在模型中我们可以用 $this->SomeOtherModel->someFunction() 来控制其他模型，或者在控制器中用 $this->SomeModel->SomeOtherModel->someFunction() 来控制其他模型。</p>
<h3>hasOne</h3>
<p>hasOne即“有一个”，比如一个User应该有一个Profile。那么我们就简单地这样声明：</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: #000000; font-weight: bold;">class</span> User <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'User'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$hasOne</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Profile'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>注意，Cake需要外键（foreign key）来实现关联（跟我的方法差不多么。。。），hasOne需要在对应的模型（本例中的Profile）中包含外键，Cake默认的外键名称是原模型小写外加“_id”，本例中就是user_id。当然了，我们可以更改这个外键的值 ，hasOne还有其他的一些参数可以修改，列举如下：</p>
<ul>
<li>className 即关联到当前模型的模型类名。本例中就是Profile。</li>
<li>foreignKey 在被关联模型中外键的名称，默认值就是当前模型类名小写后加“_id”。</li>
<li>conditions 一条SQL语句用以过滤返回的关联模型。最好在语句中加上类名，比如"Profile.approved = 1"总是比"approved = 1"好的多。</li>
<li>fields 获取关联模型数据时返回的字段列表。默认情况下返回全部。</li>
<li>order 一条SQL语句用以定义返回的关联数据的排序。</li>
<li>dependent 当这个值设置为true的时候，一旦对当前模型的某个记录调用了delete()函数并且参数cascade也设置成true，那么关联的模型记录也会被删除。本例中就是删除一个User也会删除关联给他的Profile。</li>
</ul>
<p>可以用如下形式来设置这些参数的值（其他关联都类似）：</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: #000000; font-weight: bold;">class</span> User <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'User'</span><span style="color: #339933;">;</span>          
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$hasOne</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'Profile'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'className'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Profile'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'conditions'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Profile.published'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'dependent'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span>
        <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>在控制器中用类似 $this->set('data', $this->User->find('all')) 之类的函数传递数据给视图后，我们在视图中就可以十分方便的调用各个模型了。<br />
返回的结果类似这样：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Sample results from a $this-&gt;User-&gt;find() call.</span>
&nbsp;
<span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#91;</span>User<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">121</span>
            <span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Gwoo the Kungwoo
            <span style="color: #009900;">&#91;</span>created<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2007</span><span style="color: #339933;">-</span><span style="color: #208080;">05</span><span style="color: #339933;">-</span><span style="color: #208080;">01</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">:</span><span style="color: #208080;">01</span>
        <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#91;</span>Profile<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">12</span>
            <span style="color: #009900;">&#91;</span>user_id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">121</span>
            <span style="color: #009900;">&#91;</span>skill<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Baking Cakes
            <span style="color: #009900;">&#91;</span>created<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2007</span><span style="color: #339933;">-</span><span style="color: #208080;">05</span><span style="color: #339933;">-</span><span style="color: #208080;">01</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">:</span><span style="color: #208080;">01</span>
        <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>那么我们在视图中要用User的name字段的值，就可以 $data['User']['name']，要引用Profile的skill字段的值，就可以 $data['Profile']['skill']。</p>
<h3>belongsTo</h3>
<p>用hasOne我们已经可以从User的模型和控制器中获取Profile的数据了，相反地，我们可以设置belongsTo从Profile中获取所属User的数据。如下声明：</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: #000000; font-weight: bold;">class</span> Profile <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Profile'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$belongsTo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'User'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>与hasOne不同的是，belongsTo要求在当前模型中有外键。这个外键默认是belongsTo关联的模型的类名小写再加“_id”的后缀。这个关联与hasOne有很多相同的参数，包括className、foreignKey、conditions、fields和order，此外还有一下两个参数：</p>
<ul>
<li>counterCache 把这个参数设为true会导致关联模型的一个计数字段自动更改。这个计数字段的默认名是当前模型的类名小写加上“_count”后缀，在调用save()或者delete()时这个计数值就会变化。如果在这里添一个字符串，那么就把它作为计数字段的名称。</li>
<li>counterScope 可选的条件用于确认计数字段的更新。</li>
</ul>
<p>同hasOne类似，控制器传递给视图的数组类似下面：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Sample results from a $this-&gt;Profile-&gt;find() call.</span>
&nbsp;
<span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
   <span style="color: #009900;">&#91;</span>Profile<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">12</span>
            <span style="color: #009900;">&#91;</span>user_id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">121</span>
            <span style="color: #009900;">&#91;</span>skill<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Baking Cakes
            <span style="color: #009900;">&#91;</span>created<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2007</span><span style="color: #339933;">-</span><span style="color: #208080;">05</span><span style="color: #339933;">-</span><span style="color: #208080;">01</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">:</span><span style="color: #208080;">01</span>
        <span style="color: #009900;">&#41;</span>    
    <span style="color: #009900;">&#91;</span>User<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">121</span>
            <span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Gwoo the Kungwoo
            <span style="color: #009900;">&#91;</span>created<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2007</span><span style="color: #339933;">-</span><span style="color: #208080;">05</span><span style="color: #339933;">-</span><span style="color: #208080;">01</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">:</span><span style="color: #208080;">01</span>
        <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

<h3>hasMany</h3>
<p>下面来定义一个User有很多Comment的关联，用hasMany就可以做到在获取User数据的同时得到这个用户所写的评论。同hasOne类似的是外键要放在相关联的模型中。声明hasMany的方法不再赘述。</p>
<p>hasMany在hasOne的基础上还多了如下这些参数：</p>
<ul>
<li>limit 用这个设置返回的记录的最大数量。</li>
<li>offset 获取关联数据前（在给定的conditions和order下）跳过的记录数量。</li>
<li>exclusive 当这个值设置为true的时候，模型的递归删除会调用deleteAll()函数而不是一个一个删除。这样能极大提升效率，但并不一定适合所有情况。</li>
<li>finderQuery 一条完整的SQL语句，CakePHP用来获取关联的数据。只在需要自己定义完全不同的功能时才需要。</li>
</ul>
<p>控制器传递的数组像这样：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Sample results from a $this-&gt;User-&gt;find() call.</span>
&nbsp;
<span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>  
    <span style="color: #009900;">&#91;</span>User<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">121</span>
            <span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Gwoo the Kungwoo
            <span style="color: #009900;">&#91;</span>created<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2007</span><span style="color: #339933;">-</span><span style="color: #208080;">05</span><span style="color: #339933;">-</span><span style="color: #208080;">01</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">:</span><span style="color: #208080;">01</span>
        <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#91;</span>Comment<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
                <span style="color: #009900;">&#40;</span>
                    <span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">123</span>
                    <span style="color: #009900;">&#91;</span>user_id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">121</span>
                    <span style="color: #009900;">&#91;</span>title<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> On Gwoo the Kungwoo
                    <span style="color: #009900;">&#91;</span>body<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> The Kungwooness is not so Gwooish
                    <span style="color: #009900;">&#91;</span>created<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2006</span><span style="color: #339933;">-</span><span style="color: #208080;">05</span><span style="color: #339933;">-</span><span style="color: #208080;">01</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">:</span><span style="color: #208080;">01</span>
                <span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
                <span style="color: #009900;">&#40;</span>
                    <span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">124</span>
                    <span style="color: #009900;">&#91;</span>user_id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">121</span>
                    <span style="color: #009900;">&#91;</span>title<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> More on Gwoo
                    <span style="color: #009900;">&#91;</span>body<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> But what of the ‘Nut?
                    <span style="color: #009900;">&#91;</span>created<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2006</span><span style="color: #339933;">-</span><span style="color: #208080;">05</span><span style="color: #339933;">-</span><span style="color: #208080;">01</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">41</span><span style="color: #339933;">:</span><span style="color: #208080;">01</span>
                <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>所以引用Comment时要注意用 $data['Comment'][1]等等，也可以 foreach $data['Comment'] as $single_comment 之类的。</p>
<h3>hasAndBelongsToMany</h3>
<p>最后这个有点不同，比如一个Post就“有并且属于很多”Tag，而HABTM和hasMany（用上面那个做例子）的区别就在于每个Comment被一个User拥有了之后，就不能再被别的User拥有了，而一个Tag属于一个Post之后还可以给其他的Post添加。</p>
<p>HABTM也不仅仅需要在当前模型或关联模型中的外键，它需要一个单独的包括两个模型名字的数据表，这个例子中相应的表就应该是posts_tags，一般需要3个字段——id、post_id、tags_id（哎，在Cake里写程序就记得每个表都来个id当主键，再设置成自动增长省的闹心。。。），HABTM有很多参数：
<ul>
<li>className 关联的模型类名。</li>
<li>joinTable 可以用这个参数设置关联表的名字。</li>
<li>with 这里添的是关联表对应的模型名称。默认情况下CakePHP会自动创建一个模型。本例中默认的就叫做PostsTag。这个关联表也可以像普通的模型一样使用。</li>
<li>foreignKey 当前模型中的外键值。在定义多个HABTM关联时会用到。默认值是当前模型类名小写加“_id”后缀。</li>
<li>associationForeignKey 关联模型中的外键值。在定义多个HABTM关联时会用到。默认值是关联模型的类名小写加“_id”后缀。</li>
<li>unique 如果设置为true（默认值），Cake会在添加新关联时删除已有的关联。（暂时不能理解透彻）</li>
<li>conditions fields order limit offset 和hasMany一样。</li>
<li>finderQuery deleteQuery insertQuery 分别可以添一条完整的SQL语句在获取、删除和添加关联的模型记录时使用。同样只在需要自定义的时候使用。</li>
</ul>
<p>还是看看怎么声明HABTM关联：</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>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Post <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Post'</span><span style="color: #339933;">;</span>   
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$hasAndBelongsToMany</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'Tag'</span> <span style="color: #339933;">=&gt;</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'className'</span>              <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Tag'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'joinTable'</span>              <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'recipes_tags'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'foreignKey'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'recipe_id'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'associationForeignKey'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'tag_id'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'unique'</span>                 <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'conditions'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'fields'</span>                 <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'order'</span>                  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'limit'</span>                  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'offset'</span>                 <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'finderQuery'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'deleteQuery'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'insertQuery'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span>
            <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>控制器传递给视图的数组同hasMany类似，不再赘述。</p>

	Tags:<a href="http://www.aquarhead.com/tag/aquartutorial/" title="AquarTutorial" rel="tag">AquarTutorial</a>,<a href="http://www.aquarhead.com/tag/association/" title="Association" rel="tag">Association</a>,<a href="http://www.aquarhead.com/tag/cakephp/" title="CakePHP" rel="tag">CakePHP</a>,<a href="http://www.aquarhead.com/tag/model/" title="Model" rel="tag">Model</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.aquarhead.com/2010/03/cakephp-notes-6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DarkBook Alpha</title>
		<link>http://www.aquarhead.com/2010/03/darkbook-alpha/</link>
		<comments>http://www.aquarhead.com/2010/03/darkbook-alpha/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 09:49:27 +0000</pubDate>
		<dc:creator>AquarHEAD</dc:creator>
				<category><![CDATA[Code Fortress]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[DarkBook]]></category>

		<guid isPermaLink="false">http://www.aquarhead.com/?p=801</guid>
		<description><![CDATA[修改了Layout和CSS，现在准备发布alpha版了。 点此下载。 安装指南参考CakePHP的官方手册。如果按dev模式安装的话直接解压就好了，然后在phpMyAdmin中导入压缩包中的darkbook.sql，然后向数据库中添加拥有全部权限的用户并更改app/config/database.php中相关的内容。 Tags:CakePHP,DarkBook]]></description>
			<content:encoded><![CDATA[<p>修改了Layout和CSS，现在准备发布alpha版了。</p>
<p><a href="http://www.aquarhead.com/upload/darkbook.zip">点此下载。</a></p>
<p>安装指南参考<a href="http://book.cakephp.org/view/32/Installation">CakePHP的官方手册</a>。如果按dev模式安装的话直接解压就好了，然后在phpMyAdmin中导入压缩包中的darkbook.sql，然后向数据库中添加拥有全部权限的用户并更改app/config/database.php中相关的内容。</p>

	Tags:<a href="http://www.aquarhead.com/tag/cakephp/" title="CakePHP" rel="tag">CakePHP</a>,<a href="http://www.aquarhead.com/tag/darkbook/" title="DarkBook" rel="tag">DarkBook</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.aquarhead.com/2010/03/darkbook-alpha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP自学笔记（五）：Cake中的MVC开发</title>
		<link>http://www.aquarhead.com/2010/03/cakephp-notes-5/</link>
		<comments>http://www.aquarhead.com/2010/03/cakephp-notes-5/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 13:55:37 +0000</pubDate>
		<dc:creator>AquarHEAD</dc:creator>
				<category><![CDATA[Code Fortress]]></category>
		<category><![CDATA[AquarTutorial]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://www.aquarhead.com/?p=787</guid>
		<description><![CDATA[AquarTutorial 第一期 -CakePHP自学笔记 （一）：利用Ubuntu搭建开发环境 （二）：数据库配置与连接 （三）：MVC开发模式简介 （四）：CakePHP的命名规范 >>（五）：Cake中的MVC开发]]></description>
			<content:encoded><![CDATA[<p>AquarTutorial 第一期<br />
-CakePHP自学笔记</p>
<p><a href="http://www.aquarhead.com/2010/03/cakephp-notes-1/">（一）：利用Ubuntu搭建开发环境</a><br />
<a href="http://www.aquarhead.com/2010/03/cakephp-notes-2/">（二）：数据库配置与连接</a><br />
<a href="http://www.aquarhead.com/2010/03/cakephp-notes-3/">（三）：MVC开发模式简介</a><br />
<a href="http://www.aquarhead.com/2010/03/cakephp-notes-4/">（四）：CakePHP的命名规范</a><br />
>>（五）：Cake中的MVC开发</p>
<p><-<-<-<-<-<-<-<-<-<-<-<-<-</p>
<h3>行为、组件、助手</h3>
<p>或许你已经听过很多遍那句经典的“不要重复发明轮子”了，同样，为了提高代码重用，Cake提供了Behavior（行为）、Component（组件）、Helper（助手），分别作为Model（模型）、Controller（控制器）、View（视图）的“扩展”。说白了，就跟C的标准库一样，想使用行为、组件或助手的功能，只要声明一下就OK了。</p>
<p>我目前比较常用的核心组件是Auth（认证系统），助手有Form（表格）、Session（会话控制）、html（快速创建html标签）等。</p>
<h3>使用扩展</h3>
<p>前面说过，要使用扩展，只要在模型、控制器中声明就可以了（核心助手不用声明）。示例代码：</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: #000000; font-weight: bold;">class</span> ExampleController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$components</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Auth'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>在模型中使用行为与此类似。</p>
<p>有时候，像Auth认证系统这样的组件是整站都需要的，我们可以在app/app_controller.php文件中向AppController类中引入Auth，这样所有继承自AppController的控制器也都有Auth了。也就是：</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: #000000; font-weight: bold;">class</span> AppController <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$components</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Auth'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>回调函数</h3>
<p><del datetime="2010-03-16T13:01:11+00:00">这个名词具体是什么意思我还不很明白。</del>跟某陈小讨论了一下，他给我两个网址（<a href="http://hi.baidu.com/skylin/blog/item/77a6213fddebaee555e723f2.html">CN</a>、<a href="http://www.velocityreviews.com/forums/t291572-what-is-callback-function.html">EN</a>）我还没仔细看，不过wiki上那个图片是让我懂了它为什么叫这个名字，回调的意思就是主程序调用一个库函数（级别不同），而此库函数调用了一个和主程序同样级别的函数，也即“回调”。总之呢，我现在也只用一个Callback Function就是beforeFilter()。</p>
<p>回调函数可以用来设置一些配置选项，或者在页面跳转之前执行某些动作。</p>
<p>比如我用beforeFilter来设置Auth的一些参数：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> beforeFilter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Auth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allow</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'view'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'index'</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;">Auth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loginRedirect</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>这里beforeFilter是控制器的回调函数，它在任何函数被执行前执行。</p>

	Tags:<a href="http://www.aquarhead.com/tag/aquartutorial/" title="AquarTutorial" rel="tag">AquarTutorial</a>,<a href="http://www.aquarhead.com/tag/cakephp/" title="CakePHP" rel="tag">CakePHP</a>,<a href="http://www.aquarhead.com/tag/mvc/" title="MVC" rel="tag">MVC</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.aquarhead.com/2010/03/cakephp-notes-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DarkBook原型出炉</title>
		<link>http://www.aquarhead.com/2010/03/darkbook-prototype/</link>
		<comments>http://www.aquarhead.com/2010/03/darkbook-prototype/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 00:22:45 +0000</pubDate>
		<dc:creator>AquarHEAD</dc:creator>
				<category><![CDATA[Code Fortress]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[DarkBook]]></category>

		<guid isPermaLink="false">http://www.aquarhead.com/?p=770</guid>
		<description><![CDATA[昨天终于做出了DarkBook的原型。本来寻思到哈尔滨了可以给学校那个评价系统开个头，结果呢，老蔡告诉我这个东西不着急，你们玩完回来再说吧。。。 所以呢，这两天就用Cake做了一个一直想要的整理、展示藏书的网站——也就是这个DarkBook。 P.S.CakePHP加速后的开发确实速度惊人。。。 DarkBook这个名字来源于燕仰的那句“感谢上帝给我书籍和黑夜”。 我在这个完全用于内测的版本中实现了： 用户注册、登录和登出。 个人图书馆管理页面。 添加图书。 查看他人图书馆。 列出全部用户的页面。 为了达到alpha版本，还需要努力改进的地方有： 网页的布局、CSS等。 图书的阅读状态。 编写安装手册。 本地化与国际化。 用Git或SVN发布。 有新点子了也会及时加入到这个系统中。 DarkBook: Thank God for giving me Darkness and Book. Tags:CakePHP,DarkBook]]></description>
			<content:encoded><![CDATA[<p>昨天终于做出了DarkBook的原型。本来寻思到哈尔滨了可以给学校那个评价系统开个头，结果呢，老蔡告诉我这个东西不着急，你们玩完回来再说吧。。。<br />
所以呢，这两天就用Cake做了一个一直想要的整理、展示藏书的网站——也就是这个DarkBook。</p>
<p>P.S.CakePHP加速后的开发确实速度惊人。。。</p>
<p>DarkBook这个名字来源于<a href="http://www.asyanyang.com/">燕仰</a>的那句“感谢上帝给我书籍和黑夜”。</p>
<p>我在这个完全用于内测的版本中实现了：</p>
<ul>
<li>用户注册、登录和登出。</li>
<li>个人图书馆管理页面。</li>
<li>添加图书。</li>
<li>查看他人图书馆。</li>
<li>列出全部用户的页面。</li>
</ul>
<p>为了达到alpha版本，还需要努力改进的地方有：</p>
<ul>
<li>网页的布局、CSS等。</li>
<li>图书的阅读状态。</li>
<li>编写安装手册。</li>
<li>本地化与国际化。</li>
<li>用Git或SVN发布。</li>
</ul>
<p>有新点子了也会及时加入到这个系统中。</p>
<p>DarkBook: Thank God for giving me Darkness and Book.</p>

	Tags:<a href="http://www.aquarhead.com/tag/cakephp/" title="CakePHP" rel="tag">CakePHP</a>,<a href="http://www.aquarhead.com/tag/darkbook/" title="DarkBook" rel="tag">DarkBook</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.aquarhead.com/2010/03/darkbook-prototype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>要记住</title>
		<link>http://www.aquarhead.com/2010/03/to-remember/</link>
		<comments>http://www.aquarhead.com/2010/03/to-remember/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 17:29:30 +0000</pubDate>
		<dc:creator>AquarHEAD</dc:creator>
				<category><![CDATA[Force Research]]></category>
		<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://www.aquarhead.com/?p=765</guid>
		<description><![CDATA[从最简单版本开始 持续叠代（always beta） Eat your own dog food -from Felix Ding Tags:CakePHP]]></description>
			<content:encoded><![CDATA[<p>从最简单版本开始<br />
持续叠代（always beta）<br />
Eat your own dog food </p>
<p>-from <a href="http://dingyu.me/blog/posts/view/user-friendly-2007">Felix Ding</a></p>

	Tags:<a href="http://www.aquarhead.com/tag/cakephp/" title="CakePHP" rel="tag">CakePHP</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.aquarhead.com/2010/03/to-remember/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP自学笔记（四）：CakePHP的命名规范</title>
		<link>http://www.aquarhead.com/2010/03/cakephp-notes-4/</link>
		<comments>http://www.aquarhead.com/2010/03/cakephp-notes-4/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 13:38:16 +0000</pubDate>
		<dc:creator>AquarHEAD</dc:creator>
				<category><![CDATA[Code Fortress]]></category>
		<category><![CDATA[AquarTutorial]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://www.aquarhead.com/?p=754</guid>
		<description><![CDATA[AquarTutorial 第一期 -CakePHP自学笔记 （一）：利用Ubuntu搭建开发环境 （二）：数据库配置与连接 （三）：MVC开发模式简介 >>（四）：CakePHP的命名规范]]></description>
			<content:encoded><![CDATA[<p>AquarTutorial 第一期<br />
-CakePHP自学笔记</p>
<p><a href="http://www.aquarhead.com/2010/03/cakephp-notes-1/">（一）：利用Ubuntu搭建开发环境</a><br />
<a href="http://www.aquarhead.com/2010/03/cakephp-notes-2/">（二）：数据库配置与连接</a><br />
<a href="http://www.aquarhead.com/2010/03/cakephp-notes-3/">（三）：MVC开发模式简介</a><br />
>>（四）：CakePHP的命名规范</p>
<p><-<-<-<-<-<-<-<-<-<-<-<-<-</p>
<h3>基本的命名规则</h3>
<p>上篇笔记中我们刚刚对MVC开发模式有了一个简单的认识，在进行开发之前，我们首先要熟悉CakePHP的一些命名规范，所谓命名规范也就是数据表、模型文件、模型、控制器文件、控制器、视图文件等的命名的一些规范，注意这是规范不是规定，即并不是必须的，但遵循默认的命名规范能大大加快开发速度，并减少不必要的麻烦。</p>
<p>比如你要给程序添加一系列关于物品(item)的功能，比如查看、购买等等，你最好：</p>
<ol>
<li>用items命名数据表；</li>
<li>用item.php命名模型文件，放在app/models目录下，用Item命名我们的模型（见下文）；</li>
<li>用items_controller.php命名控制器文件，放在app/controllers目录下，用Items命名我们的控制器</li>
<li>在app/views目录下建立items子目录</li>
</ol>
<p>注意有几处单复数的差别。</p>
<h3>示范代码</h3>
<p>终于到动手写写代码的时候了，首先打开app/models/item.php添加如下代码：</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: #000000; font-weight: bold;">class</span> Item <span style="color: #000000; font-weight: bold;">extends</span> AppModel<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Item'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>然后继续修改app/controllers/items_controller.php。</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: #000000; font-weight: bold;">class</span> ItemsController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Items'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>这样就完成了最基本的模型和控制器，我们所写的模型都继承AppModel类，而AppModel类又继承Model类，同样，程序中的控制器都继承AppController类，后者又继承Controller类，此处Model类和Controller类都由CakePHP的内核提供。我们可以更改AppController类，比如增加Auth组件，这样程序的所有控制器都会默认加载这个组件。</p>
<p>注意我们并没有为模型指明具体的数据表，也没有为控制器指明要使用的模型，这就是CakePHP命名规范的作用：默认情况下，单数命名的模型会自动调用复数命名的数据表（比如Item这个模型就会默认与items这个数据表交互），复数命名的控制器会自动调用单数命名的模型（所以ItemsController会默认调用Item这个模型），最后视图会自动接受控制器的相应函数返回的数据，马上就来实现一个视图。</p>
<h3>函数和视图</h3>
<p>一个控制器可能有很多函数，而每个函数都有相对应的视图，所以我们要在控制器对应的视图目录下以函数名添加视图。这里插一句CakePHP构造链接的方法，比如这个items控制器有个buy函数来实现购买功能，这时如果CakePHP的程序所在的目录是http://www.example.com/cake，那么这个buy函数对应的视图渲染的页面就是http://www.example.com/cake/items/buy，而如果我们访问http://www.example.com/cake/items，即直接访问这个控制器，Cake会默认返回index函数及其视图。</p>
<p>下面我们为Items这个控制器添加index函数，简单地返回所有items数据表中的条目。修改app/controllers/items_controller.php。</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: #000000; font-weight: bold;">class</span> ItemsController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Items'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'items'</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'all'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>这里set函数就是用来从控制器向视图传递数据的，它会以数组的形式传递数据。具体可以看<a href="http://book.cakephp.org/view/336/Creating-Post-Views">这个页面</a>。</p>
<p>然后我们创建app/views/items/index.ctp文件并添加如下内容：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;h1&gt;Show Items&lt;/h1&gt;
&nbsp;
&lt;table&gt;
	&lt;tr&gt;
		&lt;th&gt;Id&lt;/th&gt;
		&lt;th&gt;Name&lt;/th&gt;
	&lt;/tr&gt;
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;tr&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Item'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Item'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
	&lt;/tr&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;/table&gt;</pre></div></div>

<p>在数据表中添加一些数据（此处我们假定只展示数据表中id和name两项），然后访问http://localhost/caketest/items就能看到一个展示items数据的表格。</p>
<p>P.S.对于多词组的名字，命名规范如下：</p>
<ul>
<li>数据表名：user_profiles；</li>
<li>模型名：UserProfile，模型文件名：user_profile.php；</li>
<li>控制器名：UserProfilesController，控制器文件名：user_profiles_controller.php</li>
<li>视图文件目录：user_profiles</li>
</ul>

	Tags:<a href="http://www.aquarhead.com/tag/aquartutorial/" title="AquarTutorial" rel="tag">AquarTutorial</a>,<a href="http://www.aquarhead.com/tag/cakephp/" title="CakePHP" rel="tag">CakePHP</a>,<a href="http://www.aquarhead.com/tag/mvc/" title="MVC" rel="tag">MVC</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.aquarhead.com/2010/03/cakephp-notes-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP自学笔记（三）：MVC开发模式简介</title>
		<link>http://www.aquarhead.com/2010/03/cakephp-notes-3/</link>
		<comments>http://www.aquarhead.com/2010/03/cakephp-notes-3/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 03:38:58 +0000</pubDate>
		<dc:creator>AquarHEAD</dc:creator>
				<category><![CDATA[Code Fortress]]></category>
		<category><![CDATA[AquarTutorial]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://www.aquarhead.com/?p=750</guid>
		<description><![CDATA[AquarTutorial 第一期 -CakePHP自学笔记 （一）：利用Ubuntu搭建开发环境 （二）：数据库配置与连接 >>（三）：MVC开发模式简介]]></description>
			<content:encoded><![CDATA[<p>AquarTutorial 第一期<br />
-CakePHP自学笔记</p>
<p><a href="http://www.aquarhead.com/2010/03/cakephp-notes-1/">（一）：利用Ubuntu搭建开发环境</a><br />
<a href="http://www.aquarhead.com/2010/03/cakephp-notes-2/">（二）：数据库配置与连接</a><br />
>>（三）：MVC开发模式简介</p>
<p><-<-<-<-<-<-<-<-<-<-<-<-<-</p>
<h3>关于MVC</h3>
<p>CakePHP遵循MVC开发模式，所谓MVC也就是Model-View-Controller的首字母缩写，MVC开发模式把应用程序开发分成三个部分，Model即模型用于管理数据，View即视图用来制作用户界面，而Controller即控制器管理应用程序的逻辑。下图演示采用MVC开发的程序如何响应用户的请求：<br />
<div id="attachment_751" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.aquarhead.com/wp-content/uploads/2010/03/basic_mvc.png"><img src="http://www.aquarhead.com/wp-content/uploads/2010/03/basic_mvc-300x131.png" alt="MVC请求演示" title="MVC请求演示" width="300" height="131" class="size-medium wp-image-751" /></a><p class="wp-caption-text">MVC请求演示</p></div><br />
用户点击某个链接后，分发器会调用相应的控制器及函数，控制器会向模型请求数据，并做一些动作比如验证是否登录或者向模型写入数据，然后把需要展示的内容返回给视图，最后视图渲染网页返回给用户。</p>
<p>MVC的优点在于添加或移除系统组件很方便，可以说是一种迭代式开发，这样做成的系统扩展性很强，组件的重用性也很好。引述<a href="http://book.cakephp.org/cn/view/12/Benefits">CakePHP手册</a>:</p>
<blockquote><p>为什么要用 MVC模式 呢? 因为它是一个经过考验的真正的软件设计模型，它可以使程序成为可维护的、模块化的和快速开发的包。使用分离的模型(Model)、视图(View)和控制器(Controller)组织的程序是轻便的。新的特性很容易就被加入，旧的程序换上新的外观也是一下子的功夫。模块化和分离的设计使得开发者和设计者能够同时工作，这包括了快速 原型的能力。分离的设计令开发者可以修改应用的一部分而不会影响到其他部分。</p>
<p>如果你从来没有用过这种方法建立应用，适应它需要一些努力，但是我们相信一旦你使用CakePHP建立了你的第一个应用，你不会再想用其他方法建立你的应用了。</p></blockquote>
<h3>MVC下的快速开发</h3>
<p>一般来说，要给CakePHP程序添加新的功能需要如下几步：</p>
<ol>
<li>在数据库中新建一个数据表；</li>
<li>在app/models目录下新建一个Model文件；</li>
<li>在app/controllers目录下新建一个Controller文件；</li>
<li>在app/views目录下新建一个目录，在该目录中针对Controller中的每个函数新建一个View文件。</li>
</ol>
<p>这样就已经把全新的功能添加到了CakePHP中，当然，你可能还需要修改其他的MVC以便整合。</p>
<p>接下来说说CakePHP的一些命名规范，之后再用MVC给这个网站添加一个功能。</p>

	Tags:<a href="http://www.aquarhead.com/tag/aquartutorial/" title="AquarTutorial" rel="tag">AquarTutorial</a>,<a href="http://www.aquarhead.com/tag/cakephp/" title="CakePHP" rel="tag">CakePHP</a>,<a href="http://www.aquarhead.com/tag/mvc/" title="MVC" rel="tag">MVC</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.aquarhead.com/2010/03/cakephp-notes-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP自学笔记（二）：数据库配置与连接</title>
		<link>http://www.aquarhead.com/2010/03/cakephp-notes-2/</link>
		<comments>http://www.aquarhead.com/2010/03/cakephp-notes-2/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 15:35:28 +0000</pubDate>
		<dc:creator>AquarHEAD</dc:creator>
				<category><![CDATA[Code Fortress]]></category>
		<category><![CDATA[AquarTutorial]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[phpMyAdmin]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.aquarhead.com/?p=736</guid>
		<description><![CDATA[AquarTutorial 第一期 -CakePHP自学笔记 （一）：利用Ubuntu搭建开发环境 >>（二）：数据库配置与连接]]></description>
			<content:encoded><![CDATA[<p>AquarTutorial 第一期<br />
-CakePHP自学笔记</p>
<p><a href="http://www.aquarhead.com/2010/03/cakephp-notes-1/">（一）：利用Ubuntu搭建开发环境</a><br />
>>（二）：数据库配置与连接</p>
<p><-<-<-<-<-<-<-<-<-<-<-<-<-</p>
<h3>建立数据库、数据表</h3>
<p>我们用phpMyAdmin管理数据库，用浏览器打开 http://localhost/phpmyadmin 用户名输入root，密码就是安装phpMyAdmin时设置的密码。</p>
<p>登录后，新建一个数据库，比如cakedb，同时注意选择字符集。建立数据库后，默认会赋予root用户全部权限。</p>
<p>打开cakedb数据库，你可以很方便地添加数据表，字段等等。</p>
<h3>连接到数据库</h3>
<p>然后我们要让Cake和刚刚建立的数据库连接起来，这项工作只需要我们更改app/config里面的一个配置文件，进入/var/www/caketest目录，你可以把这个目录添加到自己的书签里方便以后访问，在app/config/目录中新建database.php文件并用gedit打开，我们只要修改从81行（要查看行号，可以在编辑->首选项里面打开“显示行号”）开始的几行配置：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>81
82
83
84
85
86
87
88
89
90
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$default</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'driver'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mysql'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'persistent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'host'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'login'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'root'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'somepassword'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'database'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'cakedb'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'encoding'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'utf8'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'prefix'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>其中，login和password分别添有数据库全部权限的用户的用户名和密码，database添数据库的名称，encoding是需要手动写上去的，强制用utf8编码。改好后保存，刷新 http://localhost/caketest 页面，应该是下面这样：<br />
<div id="attachment_739" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.aquarhead.com/wp-content/uploads/2010/03/screenshot_036.png"><img src="http://www.aquarhead.com/wp-content/uploads/2010/03/screenshot_036-300x196.png" alt="Database Connected" title="Database Connected" width="300" height="196" class="size-medium wp-image-739" /></a><p class="wp-caption-text">Database Connected</p></div><br />
就表明Cake已经成功地连接了数据库。</p>
<p>P.S.注意这个页面中有提示<br />
Notice (1024): Please change the value of 'Security.salt' in app/config/core.php to a salt value specific to your application [CORE/cake/libs/debugger.php, line 549]<br />
这是要你去改app/config/core.php中的'Security.salt'值（在第151行），这个值是Cake用来算Hash时（比如验证密码等）需要用到的，为了安全一定要设置一个不容易猜到的字符串。</p>

	Tags:<a href="http://www.aquarhead.com/tag/aquartutorial/" title="AquarTutorial" rel="tag">AquarTutorial</a>,<a href="http://www.aquarhead.com/tag/cakephp/" title="CakePHP" rel="tag">CakePHP</a>,<a href="http://www.aquarhead.com/tag/mvc/" title="MVC" rel="tag">MVC</a>,<a href="http://www.aquarhead.com/tag/mysql/" title="MySQL" rel="tag">MySQL</a>,<a href="http://www.aquarhead.com/tag/phpmyadmin/" title="phpMyAdmin" rel="tag">phpMyAdmin</a>,<a href="http://www.aquarhead.com/tag/ubuntu/" title="Ubuntu" rel="tag">Ubuntu</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.aquarhead.com/2010/03/cakephp-notes-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP自学笔记（一）：利用Ubuntu搭建开发环境</title>
		<link>http://www.aquarhead.com/2010/03/cakephp-notes-1/</link>
		<comments>http://www.aquarhead.com/2010/03/cakephp-notes-1/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 14:26:06 +0000</pubDate>
		<dc:creator>AquarHEAD</dc:creator>
				<category><![CDATA[Code Fortress]]></category>
		<category><![CDATA[AquarTutorial]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.aquarhead.com/?p=725</guid>
		<description><![CDATA[AquarTutorial 第一期 -CakePHP自学笔记 >>（一）：利用Ubuntu搭建开发环境]]></description>
			<content:encoded><![CDATA[<p>AquarTutorial 第一期<br />
-CakePHP自学笔记</p>
<p>>>（一）：利用Ubuntu搭建开发环境</p>
<p><-<-<-<-<-<-<-<-<-<-<-<-<-</p>
<h3>安装Ubuntu系统</h3>
<p>首先，到<a href="http://www.ubuntu.com/">Ubuntu官方网站</a>下载最新版的<a href="http://www.ubuntu.com/getubuntu/download">Ubuntu Desktop LiveCD</a>，如果速度慢也可以到<a href="http://mirrors.163.com/ubuntu-releases/">网易</a>或者<a href="http://mirrors.sohu.com/ubuntu-releases/">搜狐</a>的开源镜像站点去下载。然后把镜像刻录到一张空的CD盘上面。</p>
<p>[Choice 1]你可以直接在Windows里面安装一个Ubuntu系统，优点：安装卸载方便，缺点：速度稍慢。推荐没用过Linux的同学用这种方法装。<br />
[Choice 2]重启电脑，从光驱引导，安装Ubuntu系统，优点：完全释放系统资源，缺点：不适合新手。</p>
<p>安装完系统后，可以调整一些设置，详细的教程以后再写。</p>
<h3>安装LAMP服务器</h3>
<p>所谓LAMP Server也就是Linux操作系统+Apache服务器+MySQL数据库+PHP（以前也指Perl，现在貌似都是PHP了），在Ubuntu中安装LAMP简单至极，这也是选择Ubuntu进行开发的一个原因。</p>
<p>首先，你需要打开一个终端，即应用程序->附件->终端（英文系统里是Application->Accessories->Terminal），也就是所谓的壳（Shell）。然后输入下面的命令：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-i</span></pre></div></div>

<p>然后输入你登录时的密码，按回车应该出现root@的字样就说明你已经获得了根用户（root）的权限，在这种模式下你可以安装软件、更新系统、调整系统级的配置等等，下面我们开始安装LAMP服务器，执行：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">tasksel</pre></div></div>

<p>会出现一个蓝色的页面，用上下箭头改变高亮条的位置，调整到LAMP Server的选项上面按空格，然后按Tab键切换到OK按钮上按回车，这样Ubuntu系统就会自动安装包括Apache，MySQL和PHP等一系列程序，安装时MySQL会让你设置管理员（也叫root）密码，还有一次是确认密码，这个密码要记牢，管理数据库时要用到。</p>
<p>此时我们的服务器已经安装完成。你可以用任意浏览器访问 http://localhost 这个网址如果出现一个It works!样子的网站就说明一切OK了。附图演示：<br />
<div id="attachment_731" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.aquarhead.com/wp-content/uploads/2010/03/screenshot_037.png"><img src="http://www.aquarhead.com/wp-content/uploads/2010/03/screenshot_037-300x129.png" alt="Apache Works" title="Apache Works" width="300" height="129" class="size-medium wp-image-731" /></a><p class="wp-caption-text">Apache Works</p></div></p>
<p>接下来，我们安装phpMyAdmin这个MySQL数据库管理软件，有了它你就可以很方便地管理数据库，继续在终端里执行：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> phpmyadmin</pre></div></div>

<p>安装时会有配置选项，用空格选择apache2然后按Tab点OK，装完后会询问是否允许建立数据库，选Yes并输入数据库管理员的密码，随后会设置phpMyAdmin的密码，这个也要记住。</p>
<p>最后，我们需要修改Apache的一些配置以便让Cake能正常运行，继续执行（每次一行，第二条命令中可以使用Tab键自动补齐功能）：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">a2enmod rewrite
gedit <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>sites-enabled<span style="color: #000000; font-weight: bold;">/</span>000-default</pre></div></div>

<p>会打开一个文字编辑器，把<Directory />和<Directory /var/www>里面的AllowOverride 后面的None改成All。保存并关闭gedit。</p>
<p>重启Apache服务器，加载新配置：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 restart</pre></div></div>

<p>P.S.不要退出终端</p>
<h3>部署CakePHP的开发环境</h3>
<p>首先到Cake的官方网站下载其代码，这份笔记基于1.2.6版本，写这份笔记的时候下载地址是<a href="http://github.com/cakephp/cakephp1x/zipball/1.2.6">这个</a>。</p>
<p>下载后解压到桌面，重命名一下，下面以caketest为例继续，回到我们的终端，执行：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-R</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>你的用户名<span style="color: #000000; font-weight: bold;">/</span>Desktop<span style="color: #000000; font-weight: bold;">/</span>caketest <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">777</span> <span style="color: #660033;">-R</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www</pre></div></div>

<p>这样我们已经完成了CakePHP开发模式的部署，注意不要改动caketest目录下cake里面的文件，那里是CakePHP的核心文件。我们的第一个Cake程序将在app子目录下面开始。</p>
<p>用浏览器打开 http://localhost/caketest 或者你起的随便什么名字（比如diablo）。应该看到下面这样的网页。<br />
<div id="attachment_732" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.aquarhead.com/wp-content/uploads/2010/03/screenshot_038.png"><img src="http://www.aquarhead.com/wp-content/uploads/2010/03/screenshot_038-300x170.png" alt="CakePHP Develop Environment Done" title="CakePHP Develop Environment Done" width="300" height="170" class="size-medium wp-image-732" /></a><p class="wp-caption-text">CakePHP Develop Environment Done</p></div></p>
<p>现在你可以用两次exit命令退出终端了。</p>

	Tags:<a href="http://www.aquarhead.com/tag/aquartutorial/" title="AquarTutorial" rel="tag">AquarTutorial</a>,<a href="http://www.aquarhead.com/tag/cakephp/" title="CakePHP" rel="tag">CakePHP</a>,<a href="http://www.aquarhead.com/tag/lamp/" title="LAMP" rel="tag">LAMP</a>,<a href="http://www.aquarhead.com/tag/ubuntu/" title="Ubuntu" rel="tag">Ubuntu</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.aquarhead.com/2010/03/cakephp-notes-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP的文档该更新了</title>
		<link>http://www.aquarhead.com/2010/03/cakephp-tutorial-should-update/</link>
		<comments>http://www.aquarhead.com/2010/03/cakephp-tutorial-should-update/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 01:42:41 +0000</pubDate>
		<dc:creator>AquarHEAD</dc:creator>
				<category><![CDATA[Code Fortress]]></category>
		<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://www.aquarhead.com/?p=719</guid>
		<description><![CDATA[http://book.cakephp.org/view/333/A-Note-on-mod_rewrite 像这里一条Comment就抵过整页教程了。。。 1 - on ubuntu gutsy/hardy i used this command to enable mod_rewrite $sudo a2enmod rewrite then i modified this file vi /etc/apache2/sites-enabled/000-default and modified to be AllowOverride All on /var/www dir Tags:CakePHP]]></description>
			<content:encoded><![CDATA[<p>http://book.cakephp.org/view/333/A-Note-on-mod_rewrite</p>
<p>像这里一条Comment就抵过整页教程了。。。</p>
<blockquote><p>
1 - on ubuntu gutsy/hardy</p>
<p>i used this command to enable mod_rewrite</p>
<p>$sudo a2enmod rewrite</p>
<p>then i modified this file</p>
<p>vi /etc/apache2/sites-enabled/000-default</p>
<p>and modified to be AllowOverride All on /var/www dir</p></blockquote>

	Tags:<a href="http://www.aquarhead.com/tag/cakephp/" title="CakePHP" rel="tag">CakePHP</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.aquarhead.com/2010/03/cakephp-tutorial-should-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

