レコードがまだ存在しない場合、これらのテストデータをデータベースに保存しようとしました。しかし、新しいレコードを作成しようとすると失敗します。私は何が間違っているのか分かりません。Yiiで保存するデータが動作しない
public function actionEventReg()
{
$tmps = HUB::getEventRegistration('999881');
if(empty($tmps)){
// echo 'record does not exist';
//create new registration
$object = new EventRegistration;
$object->event_code = '206218';
$object->event_vendor_code = 'bizzabo';
$object->registration_code = '';
$object->full_name = 'test rifff';
$object->first_name = 'test';
$object->last_name = 'rifff';
$object->email = '[email protected]';
$object->phone = '';
$object->organization = '';
$object->gender = '';
$object->age_group = '';
$object->where_found = '';
$object->persona = '';
$object->paid_fee = '';
$object->is_attended = '';
$object->date_registered = '';
$object->date_payment = '';
$object->json_original = '';
$object->date_added = time();
$object->date_modified = time();
if($object->save()){
$success = 'success';
}else{
$fail = 'fail';
}
//create junk
$junk = new Junk;
$junk->code = 'test-getRegistrationNotExist-'.time();
$junk->content = sprintf('successfully insert data: %s or (%s). With first name is %s and last name is %s', $success, $fail, $object->first_name, $object->last_name);
$junk->save();
}else{
// echo 'record exist';
//create junk
$junk = new Junk;
$junk->code = 'test-getRegistrationExist-'.time();
$junk->content = sprintf('called on: %s with first name is %s and last name is %s', Yii::app()->params['masterDomain'], $tmps->first_name, $tmps->last_name);
$junk->save();
}
}
UPDATE:これは、新しいレコードを保存するためのコードが
public static function getEventRegistration($registration_code)
{
$model = EventRegistration::model()->findByAttributes(array('registration_code'=>$registration_code));
if($model!==null)
return $model;
}
次のとおりです。
この
は、登録IDが存在するかどうかをチェックするためのコードかではありません:私はユピックのようなコードを変更するには、以下のようなエラーをダンプするadviced:
public function actionBizzaboCallback()
{
$junk = new Junk;
$junk->code = 'bizzabo-bizzaboCallback-'.time();
$junk->content .= serialize($_POST);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// fetch RAW input
$json = file_get_contents('php://input');
// decode json
$objects = json_decode($json);
// expecting valid json
if (json_last_error() !== JSON_ERROR_NONE) {
die(header('HTTP/1.0 415 Unsupported Media Type'));
} else {
// check if registration exist
$tmps = HUB::getEventRegistrationByID($objects->details->items[0]->ticketId);
if(empty($tmps)){
//1. echo 'record does not exist';
//2. create new registration
$object = new EventRegistration;
$object->event_code = $objects->eventId;
$object->event_vendor_code = 'bizzabo';
$object->registration_code = $objects->details->items[0]->ticketId;
$object->full_name = sprintf('%s %s', $objects->details->items[0]->registrationForm->firstName, $objects->details->items[0]->registrationForm->lastName);
$object->first_name = $objects->details->items[0]->registrationForm->firstName;
$object->last_name = $objects->details->items[0]->registrationForm->lastName;
$object->email = $objects->details->items[0]->registrationForm->email;
$object->phone = 'null';
// $object->phone = $objects->details->items[0]->registrationForm->mobileNumber;
$object->organization = 'null';
//$object->organization = $objects->details->items[0]->registrationForm->organisation__instit;
$object->gender = 'unknown';
if(isset($objects->details->items[0]->registrationForm->gender))
{
if(stristr($objects->details->items[0]->registrationForm->gender, 'female'))
{
$gender = 'female';
}
else
{
if(stristr($objects->details->items[0]->registrationForm->gender, 'male'))
{
$gender = 'male';
}
}
}
$object->age_group = $objects->details->items[0]->registrationForm->age_group;
$object->where_found = $objects->details->items[0]->registrationForm->how_did_you_hear_abo;
$object->persona = $objects->details->items[0]->registrationForm->type_of_person;
$object->paid_fee = $objects->details->items[0]->registrationForm->ticketPaid;
$object->date_registered = $objects->details->items[0]->registrationForm->created;
$object->date_payment = $objects->details->items[0]->registrationForm->created;
$object->json_original = $json;
$object->date_added = time();
$object->date_modified = time();
if($object->save()){
$success = 'success';
}else{
var_dump($object->getErrors());
$fail = 'fail';
}
//3. create junk
$junk = new Junk;
$junk->code = 'bizzabo-getBizzaboRegistrationIntoDB-'.time();
$junk->content = sprintf('ticket id: %s does not exist. %s into database.', $objects->details->items[0]->ticketId, $fail);
}else{
//1. echo 'record exist';
//2. create junk
$junk = new Junk;
$junk->code = 'bizzabo-getBizzaboRegistrationExisted-'.time();
$junk->content = sprintf('ticket id: %s does exist. Did not update into database.',$objects->details->items[0]->ticketId);
}
$junk->content .= sprintf('Get error : %s ', $object->getErrors());
}
}
$junk->save();
}
But when I try to print $object->getErrors() in junk file, it displayed Array
()$オブジェクト - >(保存)あなたはこの' $オブジェクト - >(false)を保存しようとすることができ、 'これは、'場合は、サーバー側の検証 –