脚本宝典收集整理的这篇文章主要介绍了php – 在Sytrfony2上使用Doctrine2,Object = Entity吗?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$user = new User(1); $user->setName('Bob'); // save "bob" to database wITh ID 1 $user->setGender('Male'); // save "male" to database with ID 1 echo $user->getName(); // display bob echo $user->getGender(); // display "male"; echo $user->getDesignation() // display "Mr. Bob"
现在,在Symfony2中,使用Doctrine2,似乎Entity是一个用于与数据库建立链接的对象.所以我认为所有的setName(),setGender(),getName()& getGender()函数应该进入Bundle的Entity目录中的文件(因为那些函数来自数据库的UPDATE或SELECT数据).
但是getDesignation()呢?
public function getDesignation() { if ($this->getGender() == 'Male') return "Mr. ".$this->getName(); else return "Ms. ".$this->getName(); }
以上是脚本宝典为你收集整理的php – 在Sytrfony2上使用Doctrine2,Object = Entity吗?全部内容,希望文章能够帮你解决php – 在Sytrfony2上使用Doctrine2,Object = Entity吗?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。