【问题标题】:symfony extract data from entitysymfony 从实体中提取数据
【发布时间】:2017-11-14 01:01:48
【问题描述】:

您好,我有一个问题,我想在 Symfony 中从我的实体中检索数据,代码如下:

  public function indexAction(Request $request , $id)
    {

        $getDoctrine = $this->getDoctrine()->getManager();

        $email = $getDoctrine->getRepository('desplayBundle:people')->find($id);
        dump($email);

        return $this->render('emailBundle:Default:index.html.twig', array());
    }

我想在我的控制器中而不是在树枝中检索数据。

【问题讨论】:

  • 你用 dump($email) 检索什么?你的预期输出是什么?
  • 我从我提供的那个 id 的实体中检索该行中的所有内容,但我只想从该列中提取电子邮件
  • @erevos13 你在模型中定义了getter和setter吗?
  • 你的实体有 getter 和 setter 吗?喜欢:public function getEmail()in 你的People 实体?
  • 你尝试了什么,有什么问题?有什么错误吗?

标签: php symfony doctrine


【解决方案1】:

你想从用户那里得到电子邮件?

public function indexAction(Request $request , $id)
{

    $getDoctrine = $this->getDoctrine()->getManager();

    $user = $getDoctrine->getRepository('desplayBundle:people')->find($id);
    $email = $user->getEmail();

    return $this->render('emailBundle:Default:index.html.twig', array());
}

【讨论】:

    【解决方案2】:

    你需要确保在你的实体中你已经获取了你的数据,然后添加这行代码而不是你的转储。

     public function indexAction(Request $request , $id)
     {
    
         $getDoctrine = $this->getDoctrine()->getManager();
    
         $email = $getDoctrine->getRepository('desplayBundle:people')->find($id);
         $data = $email->getData();
    
         return $this->render('emailBundle:Default:index.html.twig', array());
     }
    

    【讨论】:

      猜你喜欢
      • 2013-12-13
      • 2013-06-15
      • 2022-06-15
      • 1970-01-01
      • 2023-04-01
      • 2019-08-31
      • 1970-01-01
      • 2014-06-06
      • 2016-03-26
      相关资源
      最近更新 更多