我有实体谁有关联OneToMany和ManyToOne,我发现开发人员有引用并把intwig和我不知道如何可见参考intwig? 我有实体
/**
* Developers
*
* @ORM\Table(name="developers")
* @ORM\Entity(repositoryClass="Artel\CustomerBundle\Entity\Repository\DevelopersRepository")
*/
class Developers extends SUser
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="CodeUserReference", mappedBy="developer", cascade={"persist"})
*/
protected $reference_developer;
有参与的实体
/**
* Coders 24 users
*
* @ORM\Table(name="code_user_reference")
* @ORM\Entity(repositoryClass="Artel\ProfileBundle\Entity\CodeUserReferenceRepository")
*/
class CodeUserReference
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Developer", inversedBy="reference_developer")
* @ORM\JoinColumn(name="user_talnet_file", nullable = true, referencedColumnName="id")
* */
protected $developer;
/**
* @ORM\Column(type="string", length=255)
*/
protected $codereference;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
protected $created_at;
动作:
$dev_actual_with_ref = $em->getRepository('ArtelProfileBundle:Developer')
->getSelfAddedDevelopersR($role);
$dev_actual_with_ref_number = count($dev_actual_with_ref);
和功能
public function getSelfAddedDevelopersR($role)
{
$qb = $this->getEntityManager()->createQueryBuilder('d');
$qb
->select('d')
->from('ArtelProfileBundle:Developer', 'd')
->leftJoin('d.reference_developer', 'm')
->where('m.codereference IS NOT NULL')
->andwhere('d.roles = :role')
->setParameter('role', $role)
->getQuery();
$query = $qb->getQuery();
$results = $query->getResult();
return $results;
}
now twig
<span class="caption-subject font-green bold uppercase">dev_actual: <b>{{ dev_actual_with_ref_number }}</b></span>
{% for devs_actual in dev_actual_with_ref %}
<li>deveoper username: <b>{{ devs_actual.username }}</b></li>
<a href="{{ path('artel_admin_index', {'id': devs_actual.id, 'ida': developer.id}) }}"><b>Edit personal information</b></a>
<li>edit_personal_information: <a href="{{ path('artel_admin_index', {'id': devs_actual.id, 'ida': developer.id}) }}"><b>{{ devs_actual.username }}</b></a></li>
<a href="{{ path('artel_admin_index', {'id': devs_actual.id, 'ida': developer.id}) }}"><b>edit professional_skills</b></a>
<li>main_skills: <a href="{{ path('artel_admin_index', {'id': devs_actual.id, 'ida': developer.id}) }}"><b>{{ devs_actual.mainskill }}</b></a></li>
{% for skills in devs_actual.skills %}
<ul>
<li>{{ skills }}</li>
</ul>
{% endfor %}
<li>reference: {{ devs_actual.reference_developer.codereference ???? }}</li>
<br>
{% endfor %}
现在我有
Method "reference_developer" for object "Artel\ProfileBundle\Entity\Developer" does not exist in ArtelProfileBundle:Dachboard:dev_actual_with_ref.html.twig at line 17
请帮助我如何在twig中的表CodeUserReference字段代码引用中获得推荐开发人员?
答案 0 :(得分:2)
你应该尝试referenceDeveloper
,因为twig调用了getter方法
因此,带有“_”的每个变量都会以大写形式获得下一个字符