I've got a problem with my code. I am just trying to insert a simple set of data to my db, but doctrine insert my attribute (telVerifCode) as NULL.
I've dumped my data and figured out, that attribute (telVerifCode) has some value in it, but after I flush it is set to NULL.
This is my controller:
$user = $this->getUser();
if ($user->getTel() != $tel || $user->getTelCode() != $telCode) {
try {
$code = $this->sendTelehopneCode($user);
} catch (\Exception $e) {
//.......
}
// update user phone verifcation fields //
$user->setTelVerifCode($code);
$user->setLastTelVerificationCodeDate(new \DateTime());
$em->persist($user);
$em->flush();
}
My ORM Mapping:
/**
* @var string
*
* @ORM\Column(name="tel_verification_code", type="string", length=255, nullable=true)
*/
protected $telVerifCode;
/**
* @var \DateTime
*
* @ORM\Column(name="last_tel_verification_code_date", type="date", nullable=true)
*/
protected $lastTelVerificationCodeDate;
sendTelehopneCode function :
private function sendTelehopneCode($user)
{
$code = strval(rand(100000, 999999));
$tel = $user->getTelCode() . $user->getTel();
$msg = 'code:' . $code;
$twilio = $this->get('twilio.api');
try {
$message = $twilio->account->messages->sendMessage(
"+14*******", // Verified Outgoing Caller ID or Twilio number
$tel, // The phone number you wish to send a message to
$msg
);
} catch (\Services_Twilio_RestException $e) {
throw $e;
}
return $code;
}
Try clearing your doctrine caches, the code looks fine and cannot be the issue.
./bin/console doctrine:cache:clear-metadata
./bin/console doctrine:cache:clear-query
./bin/console doctrine:cache:clear-result
I solved the problem, I made a listener On preUpdate one that puts the value null, I completely forgotten it :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With