在 Doctrine 中设置属性的正确方法?
在一些教程中,他们告诉您设置这样的属性:
$manager = Doctrine_Manager::getInstance();
Doctrine_Manager::getInstance()->setAttribute(
Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
并且在文档中它向您显示:
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(
Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
我想知道我应该使用哪一个?不是后一种吗?因为如何在第一个类中为单例类设置属性?第二个不是更正确吗?
in some tutorials they tell you to set up an attribute like this:
$manager = Doctrine_Manager::getInstance();
Doctrine_Manager::getInstance()->setAttribute(
Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
and in the documentation it shows you this:
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(
Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
i wonder which one i should use? isn't it the latter one? cause how can you set an attribute to a singleton class in the first one? isn't the second one more correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您甚至理解您正在查看的代码吗?
第一个代码是“错误的”。首先它分配
Doctrine_Manager
对象$managger
,然后不使用该变量。如果您想在 Doctrine_Manager 上做不止一件事,那么很自然地将此引用分配给不会弄乱您的代码的东西。如果您只想做一件事,则无需使用额外的变量,换句话说:
或
Do you even understand the code you're looking at?
The first code is "wrong". First it assigns
Doctrine_Manager
object$managger
, and then this variable is not used.If you want to do more than one thing on
Doctrine_Manager
then it's natural to get assign this reference to something that won't mess up your code. If you want to do just one thing there is no need to use extra variable, in other words:or