预祝大家十一长假快乐!
目前还不知道自己十一会干嘛,可能是:睡觉、看书、踢球、游戏、编码……今天上半天班,下午就可以闪人了,十一期间可能就懒得更新 BLOG 了,:D, 不管怎样,先祝大家十一长假快乐吧,哈哈!
目前还不知道自己十一会干嘛,可能是:睡觉、看书、踢球、游戏、编码……今天上半天班,下午就可以闪人了,十一期间可能就懒得更新 BLOG 了,:D, 不管怎样,先祝大家十一长假快乐吧,哈哈!
原文:Cake Tutorial: Books Title Example (With hasOne)
译文:Cake 教程:图书标题示例(使用 hasOne)
原文中的 $hasOne 实际上现在应该改成 $belongsTo,所以标题应该改成《图书标题示例(使用 belongsTo)》才对。这里顺便简单列举一下 Cake 目前支持的模型关联关系:
一对一(one-to-one):$hasOne 一对多(one-to-many):$hasMany 多对一(many-to-one):$belongsTo 多对多(many-to-many):$hasAndBelongsToMany
之后有时间会多翻译一些,包括 0.10.0 Docs,希望对于喜欢 Cake 的朋友有用。
Cake 马上将要发布 0.10.x.x 版本了,在 SVN 中看了新增/修改的代码,也试用了一些新代码,值得期待的地方确实很多 :D。
Larry E. Masters:
The plan for 0.10.x.x is this:
1. allow feature requests for 1 week from date of development release
2. after one week features will be frozen
3. bugs will be tracked and fixed
4. alpha release
5. bugs of alpha will be tracked and fixed
6. beta release
7. bugs of beta will be tracked and fixed
8. follow beta with release candidates, of which there will be a minimum of 4
If all goes well this will happen this week. Keep in mind there are a lot of changes that have been made in to core, and still more being done, but I feel this will become a very stable version.
The biggest proposed change is with the directory structure. We made these changes to make clear that the cake core does not need to be adjusted. Everything, needed for an app would be in the app directory. We think this will make it easier to keep your cake core up to date without messing around with your app. I would like to get input on the following images.
下边的三个图片清楚地显示了目录结构的变更:
http://phpnut.cakephp.org/proposal/cake_layout.png
http://phpnut.cakephp.org/proposal/appdir.png
http://phpnut.cakephp.org/proposal/package.png
十一期间如果有空的话,准备写一些关于 Cake 的东东,文章也好,程序也好,因为 Cake 确实有很多有趣的地方,特别是新版本又增加了很多特性,包括 AJAX 的支持等等。
Cake Framework 开始变得越来越流行了,这也得益于 Ruby On Rails 的流行,因为 Cake 是参考 ROR 写的 PHP 实现框架。而 CakePHP Data Bindings 则是可以在 Cake 中使用的一个模块,其主要作用是应用 AJAX 绑定客户端、服务器端的对象数据。这种绑定可以是客户端对象之间的绑定,客户端对象指的是 JavaScript 对象,如:
<label>Source Text Box:
<input id="example1_first" type="text" size="25" />
</label>
<label>Destination Text Box:
<input id="example1_second" type="text" size="25" />
</label>
<?= $binding->bind('example1_first.value', 'example1_second.value'); ?>
这段代码将会绑定两个客户端对象 example1_first 和 example1_second,当在第一个文本框中输入之后按“回车”,第二个文本框中就会自动填入第一个文本框所输入的文本。bind() 方法的第一个参数为“源”,第二个参数为“目标”。
接下来看看客户端与服务器端之间的对象数据绑定,服务器端对象可以是 Cake 的 Action URL,如:'/controller/action',而这个 URL 在 Cake 中最终映射到控制器的一个方法,方法名为 'action'。这个绑定之间的数据传输应用了 AJAX,Cake 中的 AJAX 类为 Prototype(之前曾经介绍过),Rail 也用这个。下面是客户端与服务器端对象数据绑定的示例:
<label>Source Text Box:
<input id="example2_first" type="text" size="25" />
</label>
<label>Target Text Box:
<input id="example2_second" type="text" size="25" />
</label>
<?= $binding->bind('example2_first.value', '/example/uppercase'); ?>
<?= $binding->bind('/example/uppercase', 'example2_second.value'); ?>
这里用了两次绑定操作,第一次是将第一个文本框 example2_first.value 绑定到服务器端的 Cake URL 中,在第一个文本框中输入之后提交会触发第一个绑定,也就是把文本框中输入的内容提交给服务器的 URL:'/example/uppercase',而 URL '/example/uppercase' 则自动映射为控制器 ExampleController 的方法 uppercase(),看看这个方法的代码:
function uppercase() {
$this->processBindingRequest();
if ($this->requestType == 'put')
$_SESSION['uppercased_value'] = strtoupper($this->requestValue);
$this->set('value', $_SESSION['uppercased_value']);
}
此方法调用 processBindingRequest() 获取提交过来的数据,然后再设置到 'value' 中。接着第二个绑定开始工作,将服务器的 '/example/uppercase' 绑定到 example2_second.value,即在第二个文本框中显示第一个文本框字符的大写形式。
如此复杂的 AJAX 通信过程,只需要几行代码即可实现,而且开发者可以将更多的精力放在控制器的 ACTION 开发上,而不需要关心 JS 对象和控制器对象是如何通信的。更多的示例参见 CakePHP Data Bindings。
今天是个特殊的日子:九一八、中秋佳节以及 shxll 生日。晚上吃的是新疆菜,给 shxll 过生日。中秋必然少不了月饼,家里的月饼都是别人送的,本来打算自己买的,但没想到这么多人送,也好,省了 :D。包装最好的当属 DOVE 的巧克力月饼,小小的,很好吃,就是太甜了。
PS:遗憾的是看不到圆月……