public function actionIndex() { $model = new Contact(); if (!empty($_POST['Contact'])) { $model = new Contact(); $model->user_id = App::getComponent('user')->getId(); $model->full_name = $_POST['Contact']['full_name']; $model->email = $_POST['Contact']['email']; $model->phone = $_POST['Contact']['phone']; if ($model->save()) { $this->redirect('contacts'); // set flash message } } $params['grid'] = (new DataGrid(['model' => $model, 'update_url' => App::getComponent('request')->createLink('contacts', 'update'), 'criteria' => ['user_id' => App::getComponent('user')->getId()], 'columns' => ['full_name' => ['alias' => 'Contact Name:', 'searchable' => true], 'email' => ['searchable' => true], 'phone' => ['searchable' => true], 'actions' => ['alias' => 'Actions:', 'content' => function ($key, $data) { // this logic should be mevoed inside the grid and automatically gets the link $url = App::getComponent('request')->createLink('contacts', 'delete', $data->id); return '<td><a class="btn btn-danger btn-sm grid-delete" href="' . $url . '"> <i class="glyphicon glyphicon-trash"></i> Delete </a></td>'; }, 'not_sortable' => true]]]))->render(); $params['model'] = $model; return $this->render('index', $params); }
public function saveContact($contactObject) { return \Models\Contact::instance()->updateOrInsert((array) $contactObject); }