当前位置: 首页>>代码示例>>PHP>>正文


PHP ContentModel::get_model_table_by_id方法代码示例

本文整理汇总了PHP中ContentModel::get_model_table_by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentModel::get_model_table_by_id方法的具体用法?PHP ContentModel::get_model_table_by_id怎么用?PHP ContentModel::get_model_table_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ContentModel的用法示例。


在下文中一共展示了ContentModel::get_model_table_by_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_archive_by_id

 /**
  * 根据content_archives_id获取文档
  * @param mixed $content_archives_id    文档编号
  * @return string $content_archives     文档
  */
 public static function get_archive_by_id($content_archives_id, $allow_cache = false)
 {
     $content_archives_name = '';
     if (!$content_archives_id) {
         return '';
     }
     //有开启缓存功能,则从缓存中取数据, 如果有数据,则直接返回结果
     if ($allow_cache && Yii::app()->cache) {
         $_cache_key = 'content.archive.row.' . $content_archives_id;
         $_r = Yii::app()->cache->get($_cache_key);
         if ($_r && is_array($_r)) {
             return $_r;
         }
     }
     $cmd = Yii::app()->db->createCommand();
     $cmd->select('a.content_archives_id, ac.content_model_id, m.content_model_name, ac.class_id, ac.class_name, a.content_archives_subject, a.content_archives_color, a.content_archives_short_subject, a.content_archives_flag, a.content_archives_jump_url, a.content_archives_source, a.content_archives_author, a.content_archives_thumb, a.content_archives_keywords, a.content_archives_summary, a.content_archives_status, a.content_archives_rank, a.content_archives_pubtime, a.content_archives_lasttime, a.content_archives_dateline')->from('{{content_archives}} a')->join('{{content_archives_classes_relating}} acr', 'acr.content_archives_id=a.content_archives_id')->join('{{content_archives_classes}} ac', 'ac.class_id=acr.class_id')->join('{{content_model}} m', 'm.content_model_id=ac.content_model_id')->where('a.content_archives_id=:content_archives_id', array('content_archives_id' => $content_archives_id));
     $_r = $cmd->queryRow();
     if ($_r) {
         //附加表结构
         $_r['content_model_colums'] = ContentModel::get_model_table_by_id($_r['content_model_id']);
         //附加表数据
         $content_model_identify = ContentModel::get_model_identify_by_id($_r['content_model_id']);
         $_sql = "SELECT * FROM {{content_addons{$content_model_identify}}} WHERE content_archives_id=:content_archives_id LIMIT 0, 1";
         $cmd = Yii::app()->db->createCommand($_sql);
         $cmd->bindValue(':content_archives_id', $content_archives_id);
         $_a_r = $cmd->queryRow();
         if (is_array($_a_r)) {
             //
             foreach ($_r['content_model_colums'] as $_k => $_v) {
                 if ($_v['content_model_field_type'] == ContentModelField::DATA_TYPE_CHECKBOX) {
                     $_a_r[$_v['content_model_field_identify']] = unserialize($_a_r[$_v['content_model_field_identify']]);
                 }
             }
             $_r = array_merge($_r, $_a_r);
         }
         unset($_a_r);
         //自定义属性
         $_r['content_archives_flag'] = explode(',', $_r['content_archives_flag']);
         //文档栏目
         $_sql = "SELECT c.*\n\t\t\t\t\tFROM {{content_archives_classes_relating}} cr\n\t\t\t\t\tINNER JOIN {{content_archives_classes}} c ON c.class_id = cr.class_id \n\t\t\t\t\tWHERE cr.content_archives_id=:content_archives_id";
         $_r['content_archives_classes'] = Yii::app()->db->createCommand($_sql)->queryAll(true, array(':content_archives_id' => $content_archives_id));
         //文档标签
         $_sql = "SELECT tags_id, tags_name\n\t\t\t\t\tFROM {{content_archives_tags}}\n\t\t\t\t\tWHERE content_archives_id=:content_archives_id\n\t\t\t\t\tORDER BY tags_id ASC";
         $_r['content_archives_tags'] = Yii::app()->db->createCommand($_sql)->queryAll(true, array(':content_archives_id' => $content_archives_id));
     }
     //有开启缓存,则把结果添加到缓存中
     if ($allow_cache && Yii::app()->cache) {
         $_cache_time_out = Setting::getSettingCache('GOODS_ROW_TIME_OUT');
         Yii::app()->cache->set($_cache_key, $_r, $_cache_time_out);
         unset($_cache_time_out, $_cache_key);
     }
     return $_r ? $_r : array();
 }
开发者ID:nbaiwan,项目名称:yav,代码行数:58,代码来源:ContentArchives.php

示例2: actionUpdate

 public function actionUpdate($id)
 {
     $archive = ContentArchives::get_archive_by_id($id, false);
     //dump($archive);exit;
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         if (!isset($_POST['Archive']) || !is_array($_POST['Archive'])) {
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('发布文档信息错误', self::MSG_ERROR, true);
         }
         if ($_POST['Archive']['content_archives_subject'] == '') {
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('文档标题不能为空', self::MSG_ERROR, true);
         }
         if (empty($_POST['Archive']['class_id']) || !is_array($_POST['Archive']['class_id'])) {
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('请至少选择一个文档栏目', self::MSG_ERROR, true);
         } else {
             foreach ($_POST['Archive']['class_id'] as $_k => $_v) {
                 if (empty($_v)) {
                     unset($_POST['Archive']['class_id'][$_k]);
                 }
             }
             if (empty($_POST['Archive']['class_id'])) {
                 $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
                 $this->message('请至少选择一个文档栏目', self::MSG_ERROR, true);
             }
         }
         /*if($_POST['Archive']['content_archives_body'] =='') {
         			$this->redirect[] = array(
         				'text' => '',
         				'href' => 'javascript:history.go(-1);',
         			);
         			$this->message('文档内容不能为空', self::MSG_ERROR, true);
         		}*/
         //自定义属性
         if (isset($_POST['Archive']['content_archives_flag']) && is_array($_POST['Archive']['content_archives_flag'])) {
             $_POST['Archive']['content_archives_flag'] = implode(',', $_POST['Archive']['content_archives_flag']);
         } else {
             $_POST['Archive']['content_archives_flag'] = '';
         }
         //发布时间
         $pubdate = $_POST['Archive']['content_archives_pubtime'] == '' ? $_SERVER['REQUEST_TIME'] : strtotime($_POST['Archive']['content_archives_pubtime']);
         $user = Yii::app()->user;
         $flag = Yii::app()->db->createCommand()->update('{{content_archives}}', array('content_archives_subject' => $_POST['Archive']['content_archives_subject'], 'content_archives_color' => $_POST['Archive']['content_archives_color'], 'content_archives_short_subject' => $_POST['Archive']['content_archives_short_subject'], 'content_archives_flag' => $_POST['Archive']['content_archives_flag'], 'content_archives_jump_url' => $_POST['Archive']['content_archives_jump_url'], 'content_archives_thumb' => $_POST['Archive']['content_archives_thumb'], 'content_archives_source' => $_POST['Archive']['content_archives_source'], 'content_archives_author' => $_POST['Archive']['content_archives_author'], 'content_archives_keywords' => $_POST['Archive']['content_archives_keywords'], 'content_archives_summary' => $_POST['Archive']['content_archives_summary'], 'content_archives_rank' => $_POST['Archive']['content_archives_rank'] ? intval($_POST['Archive']['content_archives_rank']) : 255, 'content_archives_pubtime' => $pubdate, 'content_archives_lasttime' => $_SERVER['REQUEST_TIME'], 'update_user_id' => $user->user_id), 'content_archives_id=:content_archives_id', array(':content_archives_id' => $id));
         if ($flag) {
             $content_archives_name = $_POST['Archive']['content_archives_name'];
             //文档栏目
             $_POST['Archive']['class_id'] = array_unique($_POST['Archive']['class_id']);
             $_sql_addons = "";
             $_params = array(':content_archives_id' => $id);
             foreach ($_POST['Archive']['class_id'] as $_k => $_v) {
                 $_sql_addons .= $_sql_addons ? " OR class_id=:class_id{$_k}" : "class_id=:class_id{$_k}";
                 $_params[":class_id{$_k}"] = $_v;
             }
             //删除多余栏目
             $_sql = "DELETE FROM {{content_archives_classes_relating}} WHERE content_archives_id=:content_archives_id AND NOT ({$_sql_addons})";
             Yii::app()->db->createCommand($_sql)->execute($_params);
             //取出现有栏目
             $_sql = "SELECT class_id FROM {{content_archives_classes_relating}} WHERE content_archives_id=:content_archives_id AND ({$_sql_addons})";
             $_classes = Yii::app()->db->createCommand($_sql)->queryColumn($_params);
             //去除已存在库中的栏目
             $_classes = array_diff($_POST['Archive']['class_id'], $_classes);
             //栏目入库
             foreach ($_classes as $_k => $_v) {
                 Yii::app()->db->createCommand()->insert('{{content_archives_classes_relating}}', array('content_archives_id' => $id, 'class_id' => $_v));
             }
             //标签处理
             $_sql_addons = "";
             $_params = array(':content_archives_id' => $id);
             $content_archives_tags = preg_split('/[,|,]/', $_POST['Archive']['content_archives_tags']);
             foreach ($content_archives_tags as $_k => $_v) {
                 $_sql_addons .= $_sql_addons ? " OR tags_name=:tags_name{$_k}" : "tags_name=:tags_name{$_k}";
                 $_params[":tags_name{$_k}"] = $_v;
             }
             //删除多余栏目
             $_sql = "DELETE FROM {{content_archives_tags}} WHERE content_archives_id=:content_archives_id AND NOT ({$_sql_addons})";
             Yii::app()->db->createCommand($_sql)->execute($_params);
             //取出现有栏目
             $_sql = "SELECT tags_name FROM {{content_archives_tags}} WHERE content_archives_id=:content_archives_id AND ({$_sql_addons})";
             $_tags = Yii::app()->db->createCommand($_sql)->queryColumn($_params);
             //去除已存在库中的栏目
             $_tags = array_diff($content_archives_tags, $_tags);
             //栏目入库
             foreach ($_tags as $_k => $_v) {
                 Yii::app()->db->createCommand()->insert('{{content_archives_tags}}', array('content_archives_id' => $id, 'tags_name' => $_v));
             }
             //缩略图
             //附加表信息
             $_model = ContentModel::get_model_by_id($archive['content_model_id']);
             $_columns = ContentModel::get_model_table_by_id($_model['content_model_id']);
             $_table_name = "{{content_addons{$_model['content_model_identify']}}}";
             $data = array();
             foreach ($_columns as $_k => $_v) {
                 if ($_v['content_model_field_type'] == ContentModelField::DATA_TYPE_CHECKBOX) {
                     $data[$_v['content_model_field_identify']] = serialize($_POST['Archive'][$_v['content_model_field_identify']]);
                 } else {
                     $data[$_v['content_model_field_identify']] = $_POST['Archive'][$_v['content_model_field_identify']];
                 }
             }
             Yii::app()->db->createCommand()->update($_table_name, $data, 'content_archives_id=:content_archives_id', array(':content_archives_id' => $id));
//.........这里部分代码省略.........
开发者ID:nbaiwan,项目名称:yav,代码行数:101,代码来源:ArchivesController.php


注:本文中的ContentModel::get_model_table_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。