Entity don't wan't to flush - Symfony 3.4 / Mongodb / Php
Clash Royale CLAN TAG#URR8PPP
Entity don't wan't to flush - Symfony 3.4 / Mongodb / Php
When i try to flush an entity that all work well but nothing fill my database but 0 errors... There is my controller :
/**
* @Security("is_anonymous() or is_authenticated()")
* @Route("api")
*/
class MessageUserController extends Controller
/**
*
* @RestPost(
* path = "/message/user/add",
* name = "api_message_add"
* )
*/
public function UserAddMessageAction(Request $request)
$em = $this->getDoctrine()->getManager();
$content = ($request->get('content'));
$user = $em->getRepository('AppBundle:User')->findOneBy(array('id' => ($request->get('id_user'))));
$token = $request->get('token');
$friend = $em->getRepository('AppBundle:User')->findOneBy(array('id' => ($request->get('id_friend'))));
if (!isset($content))
return new JsonResponse([
'success' => "false",
'message' => "Message non renseigné"
]);
if (!isset($token))
return new JsonResponse([
'success' => "false",
'message' => "Token non renseigné"
]);
if ($user->getToken() != $token)
return new JsonResponse([
'success' => "false",
'message' => "Bad token",
]);
if (!isset($friend) or !isset($user))
return new JsonResponse([
'success' => "false",
'message' => "Message sans propriétaire ou destinataire"
]);
$message = new MessageUser();
$message->setRead('0');
$message->setIdReceiver($friend->getId());
$message->setIdTransmitter($user->getId());
$message->setContent($content);
$dm = $this->get('doctrine_mongodb')->getManager();
$dm->persist($message);
$dm->flush();
return new JsonResponse([
'messages' => $message,
'success' => "true",
'message' => "Message ajouté"
]);
/**
*
* @RestPost(
* path = "/message/user/list",
* name = "api_message_list"
* )
*/
public function UserSeeMessageAction()
$dm = $this->get('doctrine_mongodb')->getManager();
$messages = $dm->getRepository('AppBundle:MessageUser')->find(1);
return new JsonResponse([
'messages' => $messages,
'success' => "true",
'message' => "Liste de messages"
]);
My entity :
<?php
namespace AppBundleDocument;
use DoctrineODMMongoDBMappingAnnotations as MongoDB;
/**
* @MongoDBDocument()
*/
class MessageUser
/**
* @MongoDBId
*/
protected $id;
/**
* @MongoDBField(type="string")
*/
protected $content;
/**
* @MongoDBField(type="timestamp")
*/
protected $sendAt;
/**
* @MongoDBField(type="boolean")
*/
protected $read = '0';
/**
* @MongoDBField(type="integer")
*/
protected $idTransmitter;
/**
* @MongoDBField(type="integer")
*/
protected $idReceiver;
/**
* Get id
*
* @return id $id
*/
public function getId()
return $this->id;
/**
* Set content
*
* @param string $content
* @return $this
*/
public function setContent($content)
$this->content = $content;
return $this;
/**
* Get content
*
* @return string $content
*/
public function getContent()
return $this->content;
/**
* Set sendAt
*
* @param timestamp $sendAt
* @return $this
*/
public function setSendAt($sendAt)
$this->sendAt = $sendAt;
return $this;
/**
* Get sendAt
*
* @return timestamp $sendAt
*/
public function getSendAt()
return $this->sendAt;
/**
* Set read
*
* @param boolean $read
* @return $this
*/
public function setRead($read)
$this->read = $read;
return $this;
/**
* Get read
*
* @return boolean $read
*/
public function getRead()
return $this->read;
/**
* Set idTransmitter
*
* @param integer $idTransmitter
* @return $this
*/
public function setIdTransmitter($idTransmitter)
$this->idTransmitter = $idTransmitter;
return $this;
/**
* Get idTransmitter
*
* @return integer $idTransmitter
*/
public function getIdTransmitter()
return $this->idTransmitter;
/**
* Set idReceiver
*
* @param integer $idReceiver
* @return $this
*/
public function setIdReceiver($idReceiver)
$this->idReceiver = $idReceiver;
return $this;
/**
* Get idReceiver
*
* @return integer $idReceiver
*/
public function getIdReceiver()
return $this->idReceiver;
Like if i do : http://localhost:****/api/message/user/add the reponse looks like this :
"messages": ,
"success": "true",
"message": "Message ajouté"
But if i look my database nothing if in there ... If i type "show dbs" in my terminal i can see my database to 0.0000GB
What mistake did i ? Thx for all people that will help :)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.