drxzpo70788179614 2013-02-11 21:37
浏览 22
已采纳

致命错误:调用用户的成员函数

I would like to use the get method from a User class inherit from FOSUserBundle. but i have an error :

Fatal error: Call to a member function getNom() on a non-object.

My User Class :

<?php
namespace Olr\LoanBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=255)
     *
     */
    protected $nom;

    /**
     * @ORM\Column(type="string", length=255)
     *
     */
    protected $prenom;

    /**
     * @ORM\Column(type="string", length=50)
     *
     */
    protected $adresse;

    /**
     * @ORM\Column(type="string", length=50)
     *
     */
    protected $adresse2;

    /**
     * @ORM\Column(type="string", length=5)
     *
     */
    protected $cp;

    /**
     * @ORM\Column(type="string", length=50)
     *
     */
    protected $ville;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set nom
     *
     * @param string $nom
     */
    public function setNom($nom)
    {
        $this->nom = $nom;
    }

    /**
     * Get nom
     *
     * @return string 
     */
    public function getNom()
    {
        return $this->nom;
    }

    /**
     * Set prenom
     *
     * @param string $prenom
     */
    public function setPrenom($prenom)
    {
        $this->prenom = $prenom;
    }

    /**
     * Get prenom
     *
     * @return string 
     */
    public function getPrenom()
    {
        return $this->prenom;
    }

    /**
     * Set adresse
     *
     * @param string $adresse
     */
    public function setAdresse($adresse)
    {
        $this->adresse = $adresse;
    }

    /**
     * Get adresse
     *
     * @return string 
     */
    public function getAdresse()
    {
        return $this->adresse;
    }

    /**
     * Set adresse2
     *
     * @param string $adresse2
     */
    public function setAdresse2($adresse2)
    {
        $this->adresse2 = $adresse2;
    }

    /**
     * Get adresse2
     *
     * @return string 
     */
    public function getAdresse2()
    {
        return $this->adresse2;
    }

    /**
     * Set cp
     *
     * @param string $cp
     */
    public function setCp($cp)
    {
        $this->cp = $cp;
    }

    /**
     * Get cp
     *
     * @return string 
     */
    public function getCp()
    {
        return $this->cp;
    }

    /**
     * Set ville
     *
     * @param string $ville
     */
    public function setVille($ville)
    {
        $this->ville = $ville;
    }

    /**
     * Get ville
     *
     * @return string 
     */
    public function getVille()
    {
        return $this->ville;
    }
}

from my controler :

public function invitationAction($token)
{
    $em = $this->getDoctrine()->getEntityManager();
    $entity = $em->getRepository('OlrLoanBundle:User')->findBy(array('salt'=>$token));

    return $this->render('OlrLoanBundle:Tribu:invitation.html.twig',
        array('nom'=>$entity->getNom(),
              'prenom'=>$entity->getPrenom(),
            ));
}
  • 写回答

1条回答 默认 最新

  • dongxi4235 2013-02-11 21:40
    关注

    findBy() returns an array, so you cannot invoke methods on it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办