何时在CakePhp 2.x中不使用可容忍行为 [英] When not to use Containable Behavior in CakePhp 2.x

查看:50
本文介绍了何时在CakePhp 2.x中不使用可容忍行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将可容纳行为添加到我的各种模型类中几次之后,我有一个好主意,只是将行插入到AppModel中,从而使每个模型都可容纳。然后让我感到疑惑的是,在任何情况下,特定模型具有可控行为都是不希望的或适得其反吗?

After a few times adding Containable Behavior to my various model classes, I have a good mind to simply chuck the line into AppModel instead and thus make every model Containable. Which then makes me wonder, is there any situation where it is not desirable or counterproductive for a particular model to have Containable Behavior?

推荐答案

我想说的太少了。我将可包含的内容放入App模型中:

I would say too few to be worried about. I put containable in App Model:

class AppModel extends Model {
    public $recursive = -1;
    public $actsAs = array('Containable');

}

无论如何,Containable覆盖了递归,所以您实际上并不需要将递归设置为-1,但我只是为了清楚起见。始终使用可遏制的力量可以使您成为始终仅使用所需/需要的最佳实践。对于小型应用程序,仅使用递归并忽略可包含对象并不是世界末日,但这仍然不是最佳实践。

Containable overrides recursive anyway, so you don't really need to set recursive to -1, but I do just for clarity. Always using containable forces you into the best practice of always using only what you want/need. For small apps, it's not the end of the world to just use recursive and ignore containable, but it's still not best practice.

因此,我想唯一使用参数在小型应用程序中,递归而不是可包容性的做法是,您可以节省少量的开发时间,并且不会真正显着影响性能。我肯定会默认使用容器,然后在您认为它过大的地方将其删除,而不是相反。

So, I guess the only argument for using recursive instead of containable would be that in small apps, you save yourself a tiny amount development time, and it won't really noticeably affect performance. I'd definitely go with using containable by default, and removing it where you deem it overkill, rather than the other way around.

这篇关于何时在CakePhp 2.x中不使用可容忍行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆