Ejemplo n.º 1
0
 public function actionEdit()
 {
     $this->layout = '//layouts/admin';
     $success = false;
     $id = $_REQUEST['id'];
     $model = ListsFields::model()->findByPk($id);
     $list = Lists::model()->findByPk($model->list_id);
     $this->pageTitle = is_object($model) ? $model->name : 'Новая характеристика';
     $this->breadcrumbs = array('Справочники' => array('/admin/lists'), $list->name => array('/admin/lists/edit/' . $list->id), 'Управление характеристиками' => array('/admin/lists/fields/list/' . $list->id), $model->title);
     if (isset($_POST['data']) && is_object($model)) {
         $dataArray = $_POST['data'];
         if ($dataArray['data_type'] == 'list' || $dataArray['data_type'] == 'multiple') {
             if (!isset($dataArray['rel']) || !$dataArray['rel']) {
                 $newList = new Lists();
                 $newList->setAttributes(array("name" => "Справочник для <" . $dataArray['title'] . ">"));
                 if ($newList->save()) {
                     $dataArray['rel'] = $newList->id;
                 }
             }
         }
         $model->setAttributes($dataArray);
         if ($model->save()) {
             $success = true;
         }
     }
     $this->render('edit', array('model' => $model, 'list' => $list, 'success' => $success, 'errors' => $model->errors));
 }
Ejemplo n.º 2
0
 public function actionAdd()
 {
     $this->layout = '//layouts/admin';
     $this->pageTitle = 'Новый справочник';
     $this->breadcrumbs = array('Справочники' => array('/admin/lists'), 'Новый справочник');
     $success = false;
     if (isset($_POST['data'])) {
         $model = new Lists();
         $dataArray = $_POST['data'];
         $model->setAttributes($dataArray);
         if ($model->save()) {
             $success = true;
         }
     }
     if ($success) {
         $this->redirect("/admin/lists");
     }
     if (!isset($model) || !is_object($model)) {
         $model = new Lists();
     }
     $this->render('add', array('errors' => $model->errors));
 }