protected function findModel($id)
 {
     if (($model = DefineTableField::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #2
0
 public function initContent($model, $currentChannel)
 {
     $tableName = $currentChannel->table;
     $locals = [];
     $locals['model'] = $model;
     $locals['chnid'] = $currentChannel['id'];
     $locals['currentChannel'] = $currentChannel;
     $locals['fields'] = DefineTableField::findAll(['table' => $tableName, 'is_sys' => 0]);
     return $locals;
 }
Example #3
0
 public function __construct($tableName, $isBack = true, array $attributes = [], $config = [])
 {
     $fields = DefineTableField::findAll(['table' => $tableName]);
     $formDefault = $isBack ? 'back_form_default' : 'front_form_default';
     foreach ($fields as $field) {
         $nameEn = $field['field_name'];
         $this->defineAttribute($nameEn, $field[$formDefault]);
         $this->modelAttributeLabels[$nameEn] = $field['name'];
         $this->addRule($nameEn, 'safe');
     }
     parent::__construct($attributes, $config);
 }
Example #4
0
 public static function createFieldCache()
 {
     self::createCacheFile();
     $content = '<?php' . self::$newLine;
     $tables = DefineTable::findAll();
     foreach ($tables as $table) {
         $tableName = $table['table_name'];
         $dataList = DefineTableField::findAll(['table' => $tableName]);
         foreach ($dataList as $row) {
             $content .= '$cachedFields[\'' . $tableName . '\'][\'' . $row['field_name'] . '\']=[' . self::$newLine;
             $content .= self::getCacheItem('id', $row, 'int');
             $content .= self::getCacheItem('table', $row);
             $content .= self::getCacheItem('field_name', $row);
             $content .= self::getCacheItem('name', $row);
             $content .= self::getCacheItem('type', $row);
             $content .= self::getCacheItem('length', $row, 'int');
             $content .= self::getCacheItem('is_null', $row, 'bool');
             $content .= self::getCacheItem('is_main', $row, 'bool');
             $content .= self::getCacheItem('is_sys', $row, 'bool');
             $content .= self::getCacheItem('sort_num', $row, 'int');
             $content .= self::getCacheItem('note', $row);
             $content .= self::getCacheItem('front_status', $row, 'bool');
             $content .= self::getCacheItem('front_fun_add', $row);
             $content .= self::getCacheItem('front_fun_update', $row);
             $content .= self::getCacheItem('front_fun_show', $row);
             $content .= self::getCacheItem('front_form_type', $row);
             $content .= self::getCacheItem('front_form_option', $row);
             $content .= self::getCacheItem('front_form_default', $row);
             $content .= self::getCacheItem('front_form_source', $row);
             $content .= self::getCacheItem('front_form_html', $row);
             $content .= self::getCacheItem('front_note', $row);
             $content .= self::getCacheItem('back_status', $row, 'bool');
             $content .= self::getCacheItem('back_fun_add', $row);
             $content .= self::getCacheItem('back_fun_update', $row);
             $content .= self::getCacheItem('back_fun_show', $row);
             $content .= self::getCacheItem('back_form_type', $row);
             $content .= self::getCacheItem('back_form_option', $row);
             $content .= self::getCacheItem('back_form_default', $row);
             $content .= self::getCacheItem('back_form_source', $row);
             $content .= self::getCacheItem('back_form_html', $row);
             $content .= self::getCacheItem('back_note', $row);
             $content .= "];" . self::$newLine;
         }
     }
     self::writeFile('cachedFields.php', $content);
 }
Example #5
0
 public function run($chnid, $id)
 {
     $currentChannel = Channel::findOne($chnid);
     $this->currentTableName = $currentChannel['table'];
     $attValues = $this->findModel($id);
     $model = new DefaultContent($currentChannel['table']);
     $model->setIsNewRecord(false);
     $model->attributes = $attValues;
     if ($model->load($_POST)) {
         $this->saveContent($model);
         return $this->redirect(['index', 'chnid' => $chnid]);
     } else {
         $locals = [];
         $locals['model'] = $model;
         $locals['chnid'] = $chnid;
         $locals['currentChannel'] = $currentChannel;
         $locals['fields'] = DefineTableField::findAll(['table' => $currentChannel['table'], 'is_sys' => 0]);
         $tplName = $this->getTpl($chnid, 'update');
         return $this->render($tplName, $locals);
     }
 }
 public function actionDelete($tb)
 {
     $model = $this->findModel($tb);
     $model->delete();
     DefineTableField::deleteAll(['table' => $tb]);
     $sql = SqlData::getDropTableSql($tb);
     LuLu::execute($sql);
     CacheUtility::createTableCache();
     CacheUtility::createFieldCache();
     return $this->redirect(['index']);
 }