0

Hey How Can i get any specific property from the whole object. I have this query

$portfolios = $this->getDoctrine()
    ->getRepository('MunichInnovationGroupBundle:PmPortfolios')
    ->findBy(array('user' => '1'));
foreach ($portfolios as $portfolio){
 if($portfolio.isDefault == true){
   $default_portfolio = $portfolio;
 }
  echo $portfolio.name;
}

The complete object looks like this

MunichInnovationGroup\Bundle\Entity\PmPortfolios Object
(
[id:MunichInnovationGroup\Bundle\Entity\PmPortfolios:private] => 991654b4-aa73-11e1-bdce-4a7b883b8e17
[portfolioName:MunichInnovationGroup\Bundle\Entity\PmPortfolios:private] => Umair Portfolio 1
[description:MunichInnovationGroup\Bundle\Entity\PmPortfolios:private] => Thsi is the description for Umairs portfolio 1
[permalink:MunichInnovationGroup\Bundle\Entity\PmPortfolios:private] => premalink
[sharingCode:MunichInnovationGroup\Bundle\Entity\PmPortfolios:private] => asdbnvg123dg
[shared:MunichInnovationGroup\Bundle\Entity\PmPortfolios:private] => 
[sharedPortfolioCalls:MunichInnovationGroup\Bundle\Entity\PmPortfolios:private] => 
[isDefault:MunichInnovationGroup\Bundle\Entity\PmPortfolios:private] => 1
[user:MunichInnovationGroup\Bundle\Entity\PmPortfolios:private] => Proxies\MunichInnovationGroupBundleEntityUmUsersProxy Object

How can I get the isDefault value ?

Thanks in advance

4

1 回答 1

1

如果您使用所有生成的 set/get 方法正确设置了您的实体,并且 isDefault 是一个私有属性(从 var_dump 看起来如此),您可以简单地使用

if($portfolio->getIsDefault())

为了更好地命名方法,我会在实体中编写一个方法:

public function isDefault() {
 return $this->isDefault;
}

然后使用 if($portfolio->isDefault())

于 2012-06-02T11:43:53.560 回答