예제 #1
0
 public function actionIndex()
 {
     $default_values = [['title_prefix', '', 'Название сайта(префикс)'], ['title_postfix', 'Название сайта', 'Название сайта(постфикс)'], ['uploads_path', 'uploads', 'Корневая директория для загрузки файлов'], ['thumbs_path', 'thumbs', 'Папка для превьюшек']];
     echo 'Установить все параметры по умолчанию? ' . Console::ansiFormat('[Y/n]:', [Console::FG_YELLOW]);
     $input = strtolower(readline());
     switch ($input) {
         case 'y':
             echo Console::ansiFormat('удаляем таблицу с настройками...', [Console::FG_BLUE, Console::CROSSED_OUT]) . PHP_EOL;
             \Yii::$app->db->createCommand('TRUNCATE TABLE key_value')->execute();
             foreach ($default_values as $item) {
                 $obj = new Keyvalue();
                 $obj->key = $item[0];
                 $obj->value = $item[1];
                 $obj->name = $item[2];
                 $obj->save();
             }
             echo Console::ansiFormat('успешно вернулись в каменный век!', [Console::FG_GREEN]) . PHP_EOL;
             break;
     }
 }
예제 #2
0
파일: Object.php 프로젝트: schpill/thin
 public function save()
 {
     if (isset($this->_token)) {
         $id = sha1('save' . $this->_token);
         if (Arrays::is($this->values)) {
             if (Arrays::exists($id, $this->values)) {
                 return call_user_func_array($this->values[$id], func_get_args());
             }
         }
     }
     if (isset($this->db_instance)) {
         return $this->db_instance->save($this);
     }
     if (isset($this->thin_litedb)) {
         return $this->thin_litedb->save($this);
     }
     if (isset($this->thin_kv)) {
         $db = new Keyvalue($this->thin_kv);
         return $db->save($this->to[]);
     } elseif (isset($this->thin_type)) {
         $type = $this->thin_type;
         Data::getModel($type);
         $data = [];
         if (Arrays::exists($type, Data::$_fields)) {
             $fields = Data::$_fields[$type];
             foreach ($fields as $field => $info) {
                 $data[$field] = isset($this->{$field}) ? $this->{$field} : null;
             }
             if (isset($this->id)) {
                 $newId = Data::edit($type, $this->id, $data);
             } else {
                 $newId = Data::add($type, $data);
             }
             return Data::getById($type, $newId);
         }
     } elseif (Arrays::exists('save', $this->_closures)) {
         $this->_closures['save']($this);
     }
     return $this;
 }