Answer the question
In order to leave comments, you need to log in
Why does not save in mongo?
there is a Phone class, it organizes saving to the MongoBD database, this is how saving is organized
class Phone extends ActiveRecord
{
public $contact_collection_id;
public $phone;
public $clients_id;
public $username;
public static function collectionName()
{
return 'phone';
}
/**
* @param int $contact_collection_id
* @param int $phone
* @param int $clients_id
* @param string $username
*/
public static function createPhone(int $contact_collection_id,int $phone, int $clients_id,string $username){
$phones = new static();
$phones->contact_collection_id=$contact_collection_id;
$phones->phone=$phone;
$phones->clients_id=$clients_id;
$phones->username=$username;
return $phones;
}
...
}
class PhoneFormCreateService
{
public function create(PhoneCreateForm $phoneCreateForm){
$array=['+','(',')','-'];
if(Phone::find()->where(['phone'=>$phoneCreateForm->phone,'contact_collection_id'=>$phoneCreateForm->contact_collection_id])->one())
throw new \RuntimeException('Phone already exist');
$phone=Phone::createPhone(
$phoneCreateForm->contact_collection_id,
(int)str_replace($array,'',$phoneCreateForm->phone),
$phoneCreateForm->clients_id,
$phoneCreateForm->username
);
if(!$phone->save())
throw new \RuntimeException(json_encode($phone->errors));
return $phone;
}
}
viber.phone.bulkWrite([{"type":"insert","document":[]}])
Answer the question
In order to leave comments, you need to log in
Maybe the validation fails? Try to catch the validation error:
if(!$phone->validate())
{
$errors = $model->errors;
var_dump($errors);die;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question