本文整理汇总了PHP中app\models\Contact::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Contact::save方法的具体用法?PHP Contact::save怎么用?PHP Contact::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Contact
的用法示例。
在下文中一共展示了Contact::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
public function actionCreate($type)
{
$incoming = new Incoming();
$contact = new Contact();
if ($incoming->load(Yii::$app->request->post()) && $contact->load(Yii::$app->request->post())) {
$contact->type = Contact::PERSON;
$isValid = $incoming->validate();
$isValid = $contact->validate() && $isValid;
if ($isValid) {
$incoming->save(false);
$contact->save(false);
$from = new Endpoint();
$from->type = Endpoint::FROM;
$from->doc_id = $incoming->id;
$from->contact_id = $contact->id;
$from->save(false);
return $this->redirect(['index']);
} else {
Yii::trace($contact->errors);
}
}
$incoming->type = Incoming::PERSON;
$incoming->docdate = date('Y-m-d');
return $this->render('create', ['incoming' => $incoming, 'contact' => $contact]);
}
示例2: actionCreate
/**
* Creates a new Contact model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Contact();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例3: actionCreate
/**
* Creates a new Contact model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Contact();
if (!\Yii::$app->user->can('createPost', ['post' => $model])) {
throw new NotFoundHttpException('You havent access to create item.');
}
$model->setScenario(Contact::SCENARIO_ADD_CONTACT);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例4: actionContact
public function actionContact()
{
/*$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
} else {
return $this->render('contact', [
'model' => $model,
]);
}*/
if (isset($_POST['nombre']) && isset($_POST['apellido']) && isset($_POST['email']) && isset($_POST['celular']) && isset($_POST['tipo']) && isset($_POST['mensaje'])) {
$contact = new Contact();
$contact->type = $_POST['tipo'];
$contact->name = $_POST['nombre'];
$contact->lastname = $_POST['apellido'];
$contact->email = $_POST['email'];
$contact->cellphone = $_POST['celular'];
$contact->message = $_POST['mensaje'];
if ($contact->type == 'Reclamo') {
if (isset($_POST['cedula'])) {
$contact->identity = $_POST['cedula'];
} else {
echo "no cedula";
}
}
if ($contact->save()) {
/*$body='Tipo: '.$contact->type.'\n';
if($contact->identity!=''){
$body.='Cedula: '.$contact->identity;
}
$body.='Nombre: '.$contact->name.'\n'.
'Apellido: '.$contact->lastname.'\n'.
'Email: '.$contact->lastname.'\n'.
'Cellphone: '.$contact->cellphone.'\n'.
'Mensaje: '.$contact->message.'\n';*/
if (Yii::$app->mailer->compose('contact/contact', ['contact' => $contact])->setFrom([Yii::$app->params['adminEmail'] => 'Optica los Andes'])->setTo('1800optica@ola.ec')->setSubject('Contacto Optica los Andes')->send()) {
echo "enviado";
} else {
echo "no enviado";
}
} else {
echo "no save";
print_r($contact->getErrors());
}
} else {
echo "no post";
}
}
示例5: actionCreate
/**
* Creates a new Contact model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Contact();
$infoCompany = Infocompany::findOne(['id' => 1]);
if ($model->load(Yii::$app->request->post())) {
$model->fullname = $_POST['genderName'] . " " . $model->fullname;
if ($model->save()) {
//return $this->redirect(['create', 'id' => $model->id]);
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
}
} else {
return $this->render('create', ['model' => $model, 'infoCompany' => $infoCompany]);
}
}
示例6: actionCreate
/**
* Creates a new Contact model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @return mixed
*/
public function actionCreate()
{
Yii::$app->response->format = Response::FORMAT_JSON;
// Define that response will be on json format
$model = new Contact();
$model->scenario = Contact::SCENARIO_CREATE;
// Scenarios allow us to configure which attributes are safe to massive assignment
$data = Json::decode(Yii::$app->request->post('model'));
// First of all we decode json data to data in Yii conventions
if ($model->load($data) && $model->save()) {
return ['statusCode' => 200, 'model' => $model];
} else {
// Return error 400 if no data or not created
return new HttpException(400);
}
}
示例7: actionWorkers
public function actionWorkers($id)
{
$dept = $this->loadModel($id);
$worker = new Contact(['scenario' => Contact::SCENARIO_NEW_WORKER]);
if ($worker->load(Yii::$app->request->post())) {
$worker->type = Contact::COWORKER;
$worker->dept = $dept->id;
if ($worker->save()) {
if ($worker->isChief) {
$dept->chief_id = $worker->id;
$dept->save();
}
$worker = new Contact(['scenario' => Contact::SCENARIO_NEW_WORKER]);
}
}
return $this->render('workers', ['dept' => $dept, 'worker' => $worker, 'workersDataProvider' => $this->workersDataProvider($dept->id)]);
}
示例8: actionIndex
public function actionIndex()
{
$model = new Contact();
$msgs = Contact::find()->orderBy('id DESC')->limit('50')->all();
if ($model->load(Yii::$app->request->post())) {
$model->admin_id = Yii::$app->user->id;
$model->time = time();
$model->save();
$this->redirect('contact');
}
// проверка на время публикации (1 час)
$openContactForm = true;
$restTime = 0;
foreach ($msgs as $one) {
if ($one['admin_id'] == Yii::$app->user->id && $one['time'] >= time() - 60 * 60) {
$openContactForm = false;
$restTime = ceil(($one['time'] - (time() - 60 * 60)) / 60);
break;
}
}
return $this->render('index', ['model' => $model, 'msgs' => $msgs, 'openContactForm' => $openContactForm, 'restTime' => $restTime]);
}
示例9: index
public function index()
{
$contacts = Contact::orderBy('id', 'ASC')->get();
$contact = new Contact();
if (Request::isMethod('post')) {
$validator = Validator::make(Request::all(), $this->rules);
if ($validator->passes()) {
$contact->country = Request::input('country');
$contact->countryEng = Request::input('countryEng');
$contact->address = Request::input('address');
$contact->addressEng = Request::input('addressEng');
$contact->phone = Request::input('phone');
$contact->email = Request::input('email');
$contact->enabled = Request::has('enabled');
$contact->save();
return redirect('admin/contact')->with('msg', 'Контакт был успешно создано');
} else {
return redirect('admin/contact')->withInput()->withErrors($validator);
}
}
return view('admin.contact', ['contacts' => $contacts, 'contact' => $contact]);
}
示例10: store
public function store(ContactRequest $request)
{
$contact = new Contact($request->all());
$contact->save();
return redirect('contact')->with('message', 'Contact successfully added.');
}
示例11: validate_and_save
private function validate_and_save(Request $r, \App\Models\Contact $c, $redirect = 'contact/')
{
// Do validation checks
$validator = Validator::make($r->all(), ['fname' => 'bail|required', 'lname' => 'bail|required', 'email' => ['bail', 'required', 'regex:/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}/'], 'phone' => ['regex:/\\(\\d{3}\\)\\s?\\d{3}\\-\\d{3}/'], 'birthday' => ['regex:/\\d{2}\\/\\d{2}\\/\\d{4}/'], 'zip' => ['regex:/\\d{5}(?:\\-\\d{0,4})?/']]);
// supply errors to laravel if validation fails
if ($validator->fails()) {
return redirect($redirect)->withErrors($validator)->withInput();
} else {
// or persist our contact if validation succeeds
$c->fname = $r->input('fname');
$c->lname = $r->input('lname');
$c->email = $r->input('email');
// check each field for existence and persist it if it's there
foreach (['phone', 'birthday', 'address', 'address2', 'city', 'state', 'zip'] as $field) {
if ($r->has($field)) {
$c->{$field} = $r->input($field);
}
}
// do the thing!
$c->save();
}
}
示例12: actionAddContact
/**
* Add a contact to an existing Supplier.
* @param integer $id
* @return mixed
*/
public function actionAddContact($id)
{
$supplier = $this->findModel($id);
$model = new Contact();
$model->supplier_id = $supplier->id;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $supplier->id]);
} else {
return $this->render('add-contact', ['model' => $model, 'supplier' => $supplier]);
}
}
示例13: actionImport
public function actionImport()
{
$model = new UploadForm();
$model->excelFile = UploadedFile::getInstance($model, 'excelFile');
$file = $model->upload();
if ($file) {
try {
// Handle errors gracefully.
set_error_handler(function () {
return false;
});
$member_dicts = ExcelParser::parseMembers($file->tempName);
// Restore the default error handler.
restore_error_handler();
$errors = [];
if (!$member_dicts) {
$error = Yii::t('app/error', 'The selected file could not be imported.');
$errors[] = $error;
} else {
$transaction = Yii::$app->db->beginTransaction();
$poll = $this->getPoll();
// Delete all existing members.
// foreach ($poll->members as $member) {
// $member->delete();
// }
// using new function to speed up the delete
$poll->deleteMemberData();
foreach ($member_dicts as $dict) {
$member = new Member();
$this->setPollAttributes($member);
$member->name = $dict['name'];
$member->group = $dict['group'];
if ($member->save()) {
foreach ($dict['contacts'] as $contact_dict) {
$contact = new Contact();
$contact->member_id = $member->id;
$contact->name = isset($contact_dict['name']) ? $contact_dict['name'] : null;
$contact->email = filter_var($contact_dict['email'], FILTER_SANITIZE_EMAIL);
if (!$contact->save()) {
$row = $contact_dict['row'];
$name = $contact_dict['name'];
$email = $contact_dict['email'];
$error = Yii::t('app/error', 'Row {row}: The contact with name "{name}" and email "{email}" could not be imported.', ['row' => $row, 'name' => $name, 'email' => $email]);
$errors[] = $error;
}
}
if (empty($member->contacts)) {
$member->delete();
$row = $dict['row'];
$name = $dict['name'];
$error = Yii::t('app/error', 'Row {row}: The member with name "{name}" could not be imported.', ['row' => $row, 'name' => $name]);
$errors[] = $error;
}
}
}
$transaction->commit();
}
foreach ($errors as $error) {
Yii::$app->getSession()->addFlash('import', $error);
}
} catch (Exception $e) {
throw new Exception(Yii::t('app/error', "Error Processing Request ") . $e->getMessage(), 1);
}
} else {
// todo : print error message in popup possible? e.g. on failed file upload?
Yii::$app->getSession()->addFlash('import', $model->getErrors('excelFile')[0]);
}
return $this->redirect(['poll/view', 'id' => $this->getPollId(), 'tab' => 'members']);
}
示例14: addContact
/**
* Add the data given to the database
* @return type Redirect
*/
public function addContact()
{
if (Auth::check()) {
$number = Input::get('number', true);
$info = Input::get('info', true);
$contact = new Contact();
$contact->tel = $number;
$contact->info = $info;
$contact->save();
die;
} else {
return Redirect::route('admin');
}
}
示例15: update
/**
* Update Contact attributes.
*
* @param Business $business
* @param Contact $contact
* @param array $data
* @param string $notes
*
* @return void
*/
public function update(Business $business, Contact $contact, $data = [], $notes = null)
{
$contact->firstname = array_get($data, 'firstname');
$contact->lastname = array_get($data, 'lastname');
$contact->email = array_get($data, 'email');
$contact->nin = array_get($data, 'nin');
$contact->gender = array_get($data, 'gender');
$contact->birthdate = array_get($data, 'birthdate');
$contact->mobile = array_get($data, 'mobile');
$contact->mobile_country = array_get($data, 'mobile_country');
$contact->postal_address = array_get($data, 'postal_address');
$contact->save();
self::updateNotes($business, $contact, $notes);
return $contact;
}