简体   繁体   English

控制器或模型中的Countinf函数? cakePHP

[英]Countinf function in Controller or Model ? cakePHP

just a quick question. 只是一个简单的问题。 I'm developping in cakePHP 我正在用cakePHP开发

I'd like to add a reference number to every entry in my Model, and for that i'd like a function, that will be executed in the Model's beforeSave() that will count the number of entries already created this month, and my ref number will then be YYYMMXXX, with XXX the number of this entry since day one of the month. 我想为模型中的每个条目添加一个参考号,为此,我想要一个函数,该函数将在模型的beforeSave()中执行,该函数将计算本月已经创建的条目数,引用编号将是YYYMMXXX,其中XXX是自本月第一天起的条目编号。

Should i place this counting function in the Controller or the Model ? 我应该将此计数功能放在控制器或模型中吗? I have a doubt here.. 我对此表示怀疑。

Thanks for the advice ! 谢谢你的建议 !

最好将函数放在模型中,因为代码的逻辑部分已经在模型中完成了,而且还提供了代码的可重用性,因为控制器不用于编写逻辑,因此可以使用模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM