1
votes

I want to know that How I can customize getExportFields function in Sonata Admin extend Class.

My Problem is my class fields createdAt type is datetime but I want when admin download this class data then in CSV or XLS file createdAt format DATE, not a datetime.

I want show data in CSV or XLS file through join other tables.

I searched many times on google but nothing found.

This one I try for join but I am not success-

public function getExportFields()
{
$em = $this->modelManager->getEntityManager('ABC\FroBundle\Entity\Model');
$conn = $em->getConnection();
$query = "SELECT mp.id, mp.userModel, u.email, m.model_name
        FROM model_p mp
        LEFT JOIN user u ON mp.user_id = u.id
        LEFT JOIN m_model m ON mp.model_id = m.id limit 1";
$statement = $conn->prepare($query);
$statement->execute();
$results = $statement->fetchAll();
foreach($results as $res){
    $reets = $res;
}
  $fieldsArray = $reets;
}

Any one know this type issue please help.

I asked this question on Github:- https://github.com/sonata-project/SonataAdminBundle/issues/2221

Thanks!

1

1 Answers

0
votes

Maybe the solution by @Petr Slavicek can help: Original question: symfony2 - SonataAdminBundle Exporter issue with mapped entities - Stack Overflow

Try to use the Doctrine DateTime formatter on the object e.g.:

if ($value instanceof \DateTime) {
    $value = $this->dateFormater->format('d.m.Y');
}