简体   繁体   English

我应该在使用Phalcon \\ Mvc \\ Model :: columnMap()时在phalcon中声明模型类属性吗?

[英]Should i declare model class properties in phalcon when using Phalcon\Mvc\Model::columnMap()?

Usually we need to define public properties in model class, that represent table columns. 通常我们需要在模型类中定义表示表列的公共属性。 As was said in docs and on development forums defining such public properties increases perfomance. 正如在文档和发展论坛上所说的那样,定义这样的公共属性可以提高性能。

But if we use column mapping as described here: http://docs.phalconphp.com/en/latest/reference/models.html#independent-column-mapping 但是如果我们使用这里描述的列映射: http//docs.phalconphp.com/en/latest/reference/models.html#independent-column-mapping

Should we declate public properties? 我们应该拆除公共财产吗? If yes, what properties should be defined? 如果是,应该定义哪些属性? Column names from database or their mapping names in application? 数据库中的列名称或应用程序中的映射名称?

Define properties on classes is a good practice because it reduces the overall memory consumption (this only applies for PHP >= 5.4.x). 在类上定义属性是一种很好的做法,因为它减少了整体内存消耗(这仅适用于PHP> = 5.4.x)。 So you must define properties for all classes when possible not only models. 因此,您必须尽可能为所有类定义属性,而不仅仅是模型。

This is an advanced explanation of why it reduces this increases performance: https://gist.github.com/nikic/5015323 这是为什么它降低了这种增加性能的高级解释: https//gist.github.com/nikic/5015323

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

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