欢迎光临
我们一直在努力

thinkPHP框架开发laobingcms显示文章的方法

1.创建content.php控制器

	//显示列表
    public static function indexList($where,$field,$orderby,$limit,$page){
		try{
			$res = db('article')->field($field)->alias('a')->join('column b','a.a_columnid=b.c_id')->where($where)->order($orderby)->paginate(['list_rows'=>$limit,'page'=>$page]);
		}catch(Exception $e){
			abort(config('my.error_log_code'),$e->getMessage());
		}
		return ['rows'=>$res->items(),'total'=>$res->total()];
	}

2.前台

{extend name='common/_container'} {block name="content"}
<style>
a {color:#666}
</style>
<div class="row ibox" style="background-color:#fff; margin-top:-15px;">
	<div class="col-sm-2" >
		<div class="ibox-title" style="border:none;">
			<h3 style="font-size:16px; color:#000; margin-bottom:10px;">栏目列表</h3>	
		</div>
		<ul id="treeList"></ul>
	</div>
	<div class="col-sm-10" style="border-left:10px solid #ddd;">
		<div class="ibox float-e-margins">
			<div class="ibox-title" style="border:none;">
				<h5>内容管理</h5>
				<button style="float:right; margin-top:-10px;" title="刷新页面" type="button" class="btn btn-default btn-outline" onclick="window.location.reload()" id="">
					<i class="fa fa-refresh"></i>
				</button>
			</div>
			<div class="ibox-content">
				<div class="row row-lg">
					<div class="col-sm-12">
						<div class="row" id="searchGroup">
							<div class="col-sm-3">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">文章标题</button>
									</div>
									<input type="text" class="form-control" id="title" placeholder="文章标题" />
								</div>
							</div>
							<div class="col-sm-3">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">所属分类</button>
									</div>
									<select class="form-control" id="class_id">
										<option value="">请选择</option>

										<option value="{$sql.class_id}">

										</option>

									</select>
								</div>
							</div>
							<div class="col-sm-3">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">文章状态</button>
									</div>
									<select class="form-control" id="status">
										<option value="">请选择</option>
										<option value="1">正常</option>
										<option value="0">下架</option>
									</select>
								</div>
							</div>

							<!-- search end -->
							<div class="col-sm-2">
									<button type="button" class="btn btn-primary " onclick="CodeGoods.search()" id="">
										<i class="fa fa-search"></i>&nbsp;搜索
									</button>
							</div>
						</div>
						<div class="btn-group-sm" id="CodeGoodsTableToolbar" role="group">

						<button type="button" id="add" class="btn btn-primary button-margin" onclick="CodeGoods.add()">
						<i class="fa fa-plus"></i>&nbsp;添加
						</button>

						<button type="button" id="update" class="btn btn-success button-margin" onclick="CodeGoods.update()">
						<i class="fa fa-pencil"></i>&nbsp;修改
						</button>

						<button type="button" id="delete" class="btn btn-danger button-margin" onclick="CodeGoods.delete()">
						<i class="fa fa-trash"></i>&nbsp;删除
						</button>

						<button type="button" class="btn btn-primary button-margin" onclick="CodeGoods.do()" id="">
								<i class="fa fa-check"></i>&nbsp;确定
							</button>
						</div>
						<table id="CodeGoodsTable" data-mobile-responsive="true" data-click-to-select="true">
							<thead><tr><th data-field="selectItem" data-checkbox="true"></th></tr></thead>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var CodeGoods = {id: "CodeGoodsTable",seItem: null,table: null,layerIndex: -1};

	CodeGoods.initColumn = function () {
 		return [
 			{field: 'selectItem', checkbox: true},
 			{title: '编号', field: 'a_id', visible: true, align: 'center', valign: 'middle'},
 			{title: '文章标题', field: 'a_title', visible: true, align: 'left', valign: 'middle'},
 			{title: '所属分类', field: 'c_name', visible: true, align: 'center', valign: 'middle'},
 			{title: '文章状态', field: 'a_open', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.statusFormatter},
 			{title: '发布时间', field: 'a_time', visible: true, align: 'center', valign: 'middle'},
 			// {title: '排序', field: 'sortid', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.sortidFormatter},
 			{title: '操作', field: 'a_id', visible: true, align: 'center', valign: 'middle',formatter: 'CodeGoods.buttonFormatter'},
 		];
 	};

	CodeGoods.buttonFormatter = function(value,row,index) {
		if(value){
			var str= '';
			str += '<button type="button" class="btn btn-success btn-xs" title="修改"  onclick="CodeGoods.update('+value+')"><i class="fa fa-pencil"></i>&nbsp;修改</button>&nbsp;'
			str += '<button type="button" class="btn btn-danger btn-xs" title="删除"  onclick="CodeGoods.delete('+value+')"><i class="fa fa-trash"></i>&nbsp;删除</button>&nbsp;'
			return str;
		}
	}

	CodeGoods.statusFormatter = function(value,row,index) {
		if(value !== null){
			if(value == 1){
				return '<input class="mui-switch mui-switch-animbg status'+row.a_id+'" type="checkbox" onclick="CodeGoods.updatestatus('+row.a_id+',0)" checked>';
			}else{
				return '<input class="mui-switch mui-switch-animbg status'+row.a_id+'"  type="checkbox" onclick="CodeGoods.updatestatus('+row.a_id+',1)">';
			}
		}
	}

	CodeGoods.updatestatus = function(pk,value) {
		var ajax = new $ax(Feng.ctxPath + "/Content/updateExt", function (data) {
			if ('00' === data.status) {
			} else {
				Feng.error(data.msg);
				$(".status"+pk).prop("checked",!$(".status"+pk).prop("checked"));
			}
		});
		var val = $(".status"+pk).prop("checked") ? 1 : 0;
		ajax.set('a_id', pk);
		// ajax.set('status', val);
		ajax.start();
	}

	CodeGoods.create_timeFormatter = function(value,row,index) {
		if(value){
			return formatDateTime(value);	
		}
	}

	CodeGoods.sortidFormatter = function(value,row,index) {
		return '<input type="text" value="'+value+'" onblur="CodeGoods.updatesortid('+row.a_id+',this.value)" style="width:50px; border:1px solid #ddd; text-align:center">';
	}

	CodeGoods.updatesortid = function(pk,value) {
		var ajax = new $ax(Feng.ctxPath + "/Content/updateExt", function (data) {
			if ('00' === data.status) {
			} else {
				Feng.error(data.msg);
			}
		});
		ajax.set('a_id', pk);
		// ajax.set('sortid', value);
		ajax.start();
	}

	CodeGoods.formParams = function() {
		var queryData = {};
		queryData['title'] = $("#title").val();
		queryData['class_id'] = $("#class_id").val();
		queryData['status'] = $("#status").val();
		queryData['startTime'] = $("#startTime").val();
		queryData['endTime'] = $("#endTime").val();
		return queryData;
	}

	CodeGoods.check = function () {
		var selected = $('#' + this.id).bootstrapTable('getSelections');
		if(selected.length == 0){
			Feng.info("请先选中表格中的某一记录!");
			return false;
		}else{
			CodeGoods.seItem = selected;
			return true;
		}
	};

	CodeGoods.updateExt = function (value) {
	}

	CodeGoods.add = function (value) {

		var url = location.search;
		var index = layer.open({type: 2,title: '添加',area: ['100%', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Content/add'+url});
		this.layerIndex = index;
	}

	CodeGoods.update = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '修改',area: ['100%', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Content/update?a_id='+value});
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.a_id;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据!");
					return false;
				}
				var index = layer.open({type: 2,title: '修改',area: ['100%', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Content/update?a_id='+idx});
				this.layerIndex = index;
			}
		}
	}

	CodeGoods.do = function () {

		var type =  $("#selectAction option:selected").val();
		if(type == 100){
			CodeGoods.move();
		}else{
			CodeGoods.position(type);
		}
	}

	CodeGoods.move = function (value) {
		if (this.check()) {
			var idx = '';

			$.each(CodeGoods.seItem, function() {
				idx += ',' + this.a_id;
			});

			idx = idx.substr(1);

			var class_id = $("#moveId option:selected").val();
			if(class_id == ''){
				Feng.error('请选择移动到的栏目');
			}

			Feng.confirm("是否移动选中项?", function () {
				var ajax = new $ax(Feng.ctxPath + "/Content/move", function (data) {
					if ('00' === data.status) {
						Feng.success(data.msg);
						CodeGoods.table.refresh();
					} else {
						Feng.error(data.msg);
					}
				});
				ajax.set('a_ids', idx);
				ajax.set('c_id', class_id);
				ajax.start();
			});
		}

	}

	CodeGoods.position = function (type) {
		if (this.check()) {
			var idx = '';

			$.each(CodeGoods.seItem, function() {
				idx += ',' + this.a_id;
			});

			idx = idx.substr(1);

			Feng.confirm("是否操作选中项?", function () {
				var ajax = new $ax(Feng.ctxPath + "/Content/setPosition", function (data) {
					if ('00' === data.status) {
						Feng.success(data.msg);
						CodeGoods.table.refresh();
					} else {
						Feng.error(data.msg);
					}
				});
				ajax.set('a_ids', idx);
				// ajax.set('position_id', type);
				ajax.start();
			});
		}

	}

	CodeGoods.delete = function (value) {
		if(value){
			Feng.confirm("是否删除选中项?", function () {
				var ajax = new $ax(Feng.ctxPath + "/Content/delete", function (data) {
					if ('00' === data.status) {
						Feng.success(data.msg);
						CodeGoods.table.refresh();
					} else {
						Feng.error(data.msg);
					}
				});
				ajax.set('a_ids', value);
				ajax.start();
			});
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.a_id;
				});
				idx = idx.substr(1);
				Feng.confirm("是否删除选中项?", function () {
					var ajax = new $ax(Feng.ctxPath + "/Content/delete", function (data) {
						if ('00' === data.status) {
							Feng.success(data.msg);
							CodeGoods.table.refresh();
						} else {
							Feng.error(data.msg);
						}
					});
					ajax.set('a_ids', idx);
					ajax.start();
				});
			}
		}
	}

	CodeGoods.delPosition = function (position_id,a_id) {
		Feng.confirm("确定删除推荐位吗", function () {
			var ajax = new $ax(Feng.ctxPath + "/Content/delPosition", function (data) {
				if ('00' === data.status) {
					Feng.success(data.msg);
					CodeGoods.table.refresh();
				} else {
					Feng.error(data.msg);
				}
			});
			ajax.set('a_id', a_id);
			// ajax.set('position_id', position_id);
			ajax.start();
		});

	}

	CodeGoods.search = function() {
		CodeGoods.table.refresh({query : CodeGoods.formParams()});
	};

	$(function() {
		$("#moveId").hide();
		$('#selectAction').change(function() {
			var type = $(this).val();
			if(type == 100){
				$("#moveId").show();
			}else{
				$("#moveId").hide();
			}
		});

		var defaultColunms = CodeGoods.initColumn();
		var url = location.search;
		var table = new BSTable(CodeGoods.id, Feng.ctxPath+"/Content/index"+url,defaultColunms,20);
		table.setPaginationType("server");
		table.setQueryParams(CodeGoods.formParams());
		CodeGoods.table = table.init();
	});
</script>

<script src="__PUBLIC__/static/js/plugins/layui/layui.all.js?t=1498856285724" charset="utf-8"></script>
<script>
layui.use('tree', function(){
    var tree = layui.tree;

    //渲染
    var inst1 = tree.render({
      elem: '#treeList',  //绑定元素
      data: JSON.parse('{$catagoryInfo}'),
	  showLine:false,
	  onlyIconControl:true,
	  click:function(node) {
		var queryData = CodeGoods.formParams();
		queryData['c_id'] = node.data.id;
		CodeGoods.table.refresh({query : queryData});
	  }
    });
  });

</script>
{/block}
<?php
/**
 * ============================================================================
 * * COPYRIGHT 2016-2019 xhadmin.com , and all rights reserved.
 * * WEBSITE: http://www.xhadmin.com;
 * ----------------------------------------------------------------------------
 * This is not a free software!You have not used for commercial purposes in the
 * premise of the program code to modify and use; and publication does not allow
 * any form of code for any purpose.
 * ============================================================================
 * Author: 末末 QQ:2228293408
 */

namespace appadmincontroller;
use appadminserviceCatagoryService;
use appadminmodelCatagory as CatagoryModel;
use appadmincontrollerAdmin;

class Catagory extends Admin {

	/*栏目管理*/
	function index(){

		if (!$this->request->isAjax()){
			return view('catagory/index');
		}else{
			$limit  = $this->request->post('limit', 0, 'intval');
			$offset = $this->request->post('offset', 0, 'intval');
			$page   = floor($offset / $limit) +1 ;

			$where = [];
			$field = '*';
			$orderby = 'c_id asc';

			$res = CatagoryService::indexList(formatWhere($where),$field,$orderby,$limit,$page);

		    $res['rows'] = formartList(['c_id', 'c_parentid', 'c_webname','c_webname'],$res['rows']);

			return json($res);
		}
	}

	/*修改排序*/
	function updateExt(){
		$postField = 'c_id,c_order';
		$data = $this->request->only(explode(',',$postField),'post',null);
		if(!$data['c_id']) $this->error('参数错误');
		dump($data);exit;
		try{
			CatagoryModel::update($data);
		}catch(Exception $e){
			abort(config('my.error_log_code'),$e->getMessage());
		}
		return json(['status'=>'00','msg'=>'操作成功']);
	}

	/*添加*/
	function add(){
		if (!$this->request->isPost()){
			 $class_id = $this->request->get('c_id','','intval');
//			 	dump($class_id);
			  $info = CatagoryModel::find($class_id);
			  // dump($info);exit;
              $data["c_parentid"]= $info->c_id;
              $data["c_name"] = $info->c_name;

              $data["c_columntemp"] = $info->c_columntemp;
              $data["c_articletemp"] = $info->c_articletemp;
              $data["c_nav"] = $info->c_articletemp;
			  $this->view->assign('info',$data);

			// $this->view->assign('tpList',CatagoryService::tplList($default_themes));
			return view('catagory/add');
		}else{
			$data = $this->request->post();
			  $data['c_parpath']=0;
			// dump($data);exit;
			$res = CatagoryService::add($data);
			// exit;
			return json(['status'=>'00','msg'=>'添加成功']);
		}
	}

	/*修改*/
	function update(){
		if (!$this->request->isPost()){
			$class_id = $this->request->get('c_id','','intval');
			if(!$class_id) $this->error('参数错误');
			// $default_themes = config('xhadmin.default_themes') ? config('xhadmin.default_themes') : 'index';

			// $this->view->assign('tpList',CatagoryService::tplList($default_themes));
			$this->view->assign('info',checkData(CatagoryModel::find($class_id)));
			return view('catagory/update');
		}else{
			$data = $this->request->post();
			// dump($data);exit;
			$data['c_key']=$data['status'];
			if($data['c_id'] == $data['c_parentid']) $this->error('当前分类不能作为父分类');
			CatagoryService::update($data);
			return json(['status'=>'00','msg'=>'修改成功']);
		}
	}

	/*删除*/
	function delete(){
		$idx =  $this->request->post('c_ids', '', 'serach_in');
		if(!$idx) $this->error('参数错误');
		try{
			CatagoryModel::destroy(['c_id'=>explode(',',$idx)]);
		}catch(Exception $e){
			abort(config('my.error_log_code'),$e->getMessage());
		}
		return json(['status'=>'00','msg'=>'操作成功']);
	}

	//排序上下移动操作
	function setSort(){
		$class_id  = $this->request->post('c_order', 0, 'intval');

		$type  = $this->request->post('type', 0, 'intval');
		// echo $type;exit;
		if(empty($class_id) || empty($type)) $this->error('参数错误');
		CatagoryService::setSort($class_id,$type);
		return json(['status'=>'00','msg'=>'操作成功']);

	}

}

前台显示:tp开发80cms显示文章

赞(0) 打赏
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 ivillcn@qq.com 举报,一经查实,本站将立刻删除。
文章名称:《thinkPHP框架开发laobingcms显示文章的方法》
文章链接:https://www.bilibiji.com/article/170.html

评论 抢沙发

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

微信扫一扫

登录

找回密码

注册