0
User 클래스의 get 메서드를 FOSUserBundle에서 상속 받고 싶습니다. 내 CONTROLER에서치명적인 오류 : 사용자의 멤버 함수 호출
<?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;
}
}
:
Fatal error: Call to a member function getNom() on a non-object.
내 사용자 클래스 :하지만 난 오류가 당신이 메소드를 호출 할 수
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) { [0] => 객체 (Olr \ LoanBundle \ Entity \ User) # 552 (012)에 대한 이해 [[ "id": protected] = > INT (6) [ "NOM"보호] => 끈 (7) "Romeyer" [ "prenom"보호] => 끈 (7) "올리비에" ... }} – Olivier
글쎄, 그것은 배열이고 ... 음, 모든 배열 http://php.net/language.types.array와 마찬가지로 접근 할 수있다. 그래서 당신의 경우에는 : $ entity [0] -> getNom()'예를 들어 . 또는'current ($ entity) -> getNom()'. 또는'list ($ entity) = $ entity; $ 엔티티 -> getNom();'. 항상 빈 배열에주의하십시오. – KingCrunch
반환 값은'Olr \ LoanBundle \ Entity \ User' 객체의 배열입니다. 소금과 관련된 각 레코드가 고유하다는 것을 알고 있다면, 배열 대신 하나의 객체를 반환하기 위해'findOneBy()'를 대신 사용할 수 있습니다. – theunraveler