发新话题
打印

CakePHP编程风格的意淫

CakePHP编程风格的意淫

作者:老王

查找一个对象:

A: $this->Article->find('Article.id = 123');
B: $this->Article->id = 123; $this->Article->read();

保存一个对象:

A: $this->Article->save($this->data);
B: $this->Article->create($this->data); $this->Article->save();

我一般都是B风格,不过这意义也不大,像我说的,基本属于意淫的范畴。

TOP

我觉得activerecord这样用更好看,呵呵

$article = new Article();
$article->title = $title;
$article->save();

TOP

引用:
原帖由 jaycn 于 2007-11-30 20:02 发表
我觉得activerecord这样用更好看,呵呵

$article = new Article();
$article->title = $title;
$article->save();
可惜CakePHP缺省的AR实现使用的是$this->data容器,和传统的AR不一样。

TOP

$this->Article->create($this->data);后,如果我想改变其中的数据,怎么操作??
帮助像偶一样的菜鸟

TOP

引用:
原帖由 永动机 于 2007-11-30 20:03 发表
$this->Article->create($this->data);后,如果我想改变其中的数据,怎么操作??
$this->Article->set(xxx);

TOP

$this->User->set('password',md5($this->data['User']['password']));
is ok!

开始写成$this->set了,faint!
帮助像偶一样的菜鸟

TOP

复制内容到剪贴板
代码:
B: $this->Article->id = 123; $this->Article->read();
$this->Article->set('id', 123);

这样的风格的意淫, 可能会好点.
管理者务必保证团队能够专心于既定目标而不受外界干扰。

TOP

发新话题