echo $field['content_model_field_id']; ?> ]" value="<?php echo $field['content_model_field_rank']; ?> " size="3" maxlength="3" /></td> <td><?php echo $field['content_model_field_name']; ?> </td> <td><?php echo $field['content_model_field_identify']; ?> </td> <td><?php echo ContentModelField::get_field_data_types($field['content_model_field_type']); ?> </td> <td><?php echo $field['content_model_field_max_length']; ?> </td> <td align="center"> <a href="<?php echo url($this->module->id . "/Content/Model/{$field['content_model_id']}/Field/{$field['content_model_field_id']}/Update"); ?> ">编辑</a> <?php if ($field['content_model_field_is_system'] == 1) { echo '删除';
/** * 强制更新缓存 */ public static function update_cache() { // self::$__fields = null; // if (isset(Yii::app()->cache)) { $_fields = self::read_fields_array(); Yii::app()->cache->set('content.model.fields', $_fields); } return true; }
?> " /> 提示信息。 </dd> </dl> </td> </tr> <tr> <td colspan="5"> <dl> <dt>数据类型:</dt> <dd> <?php $k = 0; foreach (ContentModelField::get_field_data_types() as $_k => $_v) { $k++; $selected = $_k == $field['content_model_field_type'] ? ' checked="checked"' : ''; echo "<div class=\"radio_text\"><input type=\"radio\" name=\"Field[content_model_field_type]\" id=\"Field_content_model_field_type_{$_k}\" value=\"{$_k}\"{$selected} /><label for=\"Field_content_model_field_type_{$_k}\">{$_v}</label></div>"; if ($k % 4 == 0) { echo "<br />"; } } ?> </dd> </dl> </td> </tr> <tr> <td colspan="5">
public function actionCreate($collect_model_id) { $model = CollectModel::get_model_by_id($collect_model_id); //当前采集模型 if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!isset($_POST['Fields']) || !is_array($_POST['Fields'])) { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('保存采集字段信息错误', self::MSG_ERROR, true); } if ($_POST['Fields']['collect_fields_name'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('采集字段名称不能为空', self::MSG_ERROR, true); } if ($_POST['Fields']['collect_fields_type'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('采集字段类型不能为空', self::MSG_ERROR, true); } /* if($_POST['Fields']['collect_fields_belong'] =='') { $this->redirect[] = array( 'text' => '', 'href' => 'javascript:history.go(-1);', ); $this->message('字段归属不能为空', self::MSG_ERROR, true); }*/ if ($_POST['Fields']['collect_fields_identify'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('采集字段标识不能为空', self::MSG_ERROR, true); } /* if($_POST['Fields']['collect_fields_identify'] =='collect_content_id') { $this->redirect[] = array( 'text' => '', 'href' => 'javascript:history.go(-1);', ); $this->message('采集字段标识已存在', self::MSG_ERROR, true); }*/ if (!preg_match("/^[a-z]([a-z\\d\\_]+?)\$/", $_POST['Fields']['collect_fields_identify'])) { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('采集字段标识必须是以字母开头的字母、数字、下划线', self::MSG_ERROR, true); } if (CollectModelField::get_fields_id_by_identify($collect_model_id, $_POST['Fields']['collect_fields_identify'])) { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('采集字段标识重复', self::MSG_ERROR, true); } $flag = Yii::app()->db->createCommand()->insert('{{collect_model_fields}}', array('collect_fields_id' => 0, 'collect_model_id' => $collect_model_id, 'collect_fields_name' => $_POST['Fields']['collect_fields_name'], 'collect_fields_identify' => $_POST['Fields']['collect_fields_identify'], 'collect_fields_status' => CollectModelField::STAT_STATUS_NORMAL, 'collect_fields_type' => $_POST['Fields']['collect_fields_type'], 'content_model_field_id' => $_POST['Fields']['content_model_field_id'], 'collect_fields_rank' => $_POST['Fields']['collect_fields_rank'], 'collect_fields_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_fields_dateline' => $_SERVER['REQUEST_TIME'])); $collect_model_identify = CollectModel::get_model_identify_by_id($collect_model_id); if ($_POST['Fields']['collect_fields_type'] == 1) { //单行文本 $f = " VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ;"; } if ($_POST['Fields']['collect_fields_type'] == 2) { //多行文本 $f = " TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ;"; } if ($_POST['Fields']['collect_fields_type'] == 3) { //日期时间 $f = " DATETIME NOT NULL ;"; } $sql = "ALTER TABLE `collect_model_addons{$collect_model_identify}` ADD `" . $_POST['Fields']['collect_fields_identify'] . "` " . $f; Yii::app()->db->createCommand($sql)->execute(); if ($flag) { $collect_fields_id = Yii::app()->db->getLastInsertID(); $collect_fields_name = $_POST['Fields']['collect_fields_name']; //记录操作日志 $user = Yii::app()->user; $message = '{user_name}添加采集字段{collect_fields_name}'; $data = array('user_id' => $user->id, 'user_name' => $user->name, 'collect_fields_name' => $collect_fields_name, 'addons_data' => array('collect_fields_id' => $collect_fields_id)); AdminLogs::add($user->id, 'Collect/Model/Fields', $collect_fields_id, 'Insert', 'success', $message, $data); if (!isset($_GET['ajax'])) { $this->redirect[] = array('text' => '', 'href' => url($this->module->id . "/Collect/Model/{$collect_model_id}/Fields/Index")); $this->message('添加采集字段完成', self::MSG_SUCCESS, true); } } else { //记录操作日志 $user = Yii::app()->user; $message = '{user_name}添加采集字段{collect_fields_name}失败'; $data = array('user_id' => $user->id, 'user_name' => $user->name, 'collect_fields_name' => $_POST['Fields']['collect_fields_name'], 'addons_data' => array('fields' => $_POST['Fields'])); AdminLogs::add($user->id, 'Collect/Model/Fields', 0, 'Insert', 'failure', $message, $data); $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('添加采集字段失败', self::MSG_ERROR, true); } } $field = array('collect_fields_id' => 0, 'collect_fields_name' => '', 'collect_fields_identify' => '', 'collect_fields_rank' => 255); $this->render('create', array('field' => $field, 'field_types' => CollectModelField::get_field_types(), 'content_model_fields' => ContentModelField::get_fields_by_cache($model['content_model_id']), "collect_model_id" => $collect_model_id)); }
/** * * @param unknown_type $content_model_id */ public function actionIndex($content_model_id) { if ($_SERVER['REQUEST_METHOD'] == 'POST') { //保存修改 if (!is_array($_POST['Field']['content_model_field_rank'])) { $_POST['Field']['content_model_field_rank'] = array(); } foreach ($_POST['Field']['content_model_field_rank'] as $_k => $_v) { $flag = Yii::app()->db->createCommand()->update('{{content_model_fields}}', array('content_model_field_rank' => $_POST['Field']['content_model_field_rank'][$_k] ? intval($_POST['Field']['content_model_field_rank'][$_k]) : 255), 'content_model_field_id=:content_model_field_id', array(':content_model_field_id' => $_k)); if ($flag) { //记录操作日志 $message = '{user_name}修改了内容模型({model_name})字段({field_name})排序'; $data = array('user_id' => Yii::app()->user->id, 'user_name' => Yii::app()->user->name, 'model_name' => ContentModel::get_model_name_by_id($content_model_id), 'field_name' => ContentModelField::get_field_name_by_id($_v), 'addons_data' => $_POST); AdminLogs::add(Yii::app()->user->id, 'Content/Model/Field', $_k, 'Modify', 'success', $message, $data); } } ContentModelField::update_cache(); //$this->refresh(); $this->redirect[] = array('text' => '', 'href' => url($this->module->id . "/Content/Model/{$content_model_id}/Field/Index")); $this->message('修改字段排序完成', self::MSG_SUCCESS, true); } $fields = ContentModelField::get_fields_by_cache($content_model_id); $this->render('index', array('fields' => $fields, "content_model_id" => $content_model_id)); }