Get a value from a multidimensional object PHP Symfony Doctrine

0

Hi, I'm a beginner and I want to get the value found in the following object specifically in: [id:AppBundle\Entity\BlogPost:private] => 1 and store it in a variable.

The first part is the result of print_r and the second part is the code, thanks

 AppBundle\Entity\BlogPost Object
    (
        [id:AppBundle\Entity\BlogPost:private] => 1
        [title:AppBundle\Entity\BlogPost:private] => Primera entrada de Blog
        [content:AppBundle\Entity\BlogPost:private] => Lorem Ipsum
        [createdAt:AppBundle\Entity\BlogPost:private] => DateTime Object
            (
                [date] => 2011-01-01 00:00:00.000000
                [timezone_type] => 3
                [timezone] => Europe/Berlin
            )

    )


public function showAction($id)
{
    $blogentry = $this->getDoctrine()
        ->getRepository('AppBundle:BlogPost')
        ->find($id);
    echo "<pre>";
    print_r($blogentry);
    echo "</pre>";


    if (!$blogentry) {
        throw $this->createNotFoundException(
            'No product found for id '. $blogentry
        );
    }

    return $this->render('AppBundle:default:show.html.twig', array(
        'blogentry' => $blogentry
    ));
}
    
asked by Nefi López 17.11.2016 в 17:21
source

1 answer

1

As I see the id is accessible by the getId() method:

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

Source

    
answered by 23.11.2016 / 16:38
source