Ich habe ein Problem mit meinem Code. Ich versuche nur, eine einfache Menge von Daten in meine db einzufügen, aber doctrine fügt mein Attribut (telVerifCode) als NULL ein.Wert auf null auf flush Doktrin gesetzt
Ich habe meine Daten ausgegeben und herausgefunden, dass das Attribut (telVerifCode) einen gewissen Wert darin hat, aber nach dem Flush wird es auf NULL gesetzt.
Dies ist mein 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();
}
Meine 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 Funktion:
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;
}
Gibt es eine Datentypkonflikt zwischen Originaldaten und ORM-config (string)? – Jeet
$ code ist ein string data – ghazi2008
Dann macht es keinen Sinn, 'null' auf' flush() 'zu sein. Kannst du den gesamten Code von dieser Methode in den Controller setzen? – Jeet