thinkphp5之fastafmin筆記
阿新 • • 發佈:2018-11-28
fastafmin筆記
個人推薦的開源框架:官網文件:https://doc.fastadmin.net/docs/controller.html
控制器
public function _initialize() { parent::_initialize(); $this->model = model('AppointmentActivity'); //查詢場館列表 $venue_model = model('Venue'); $venue_list = $venue_model->select(); $venue_list = Collection($venue_list)->toArray(); $this->view->assign("venueList", $venue_list); $this->view->assign("isListList", $this->model->getIsListList()); }
html
<div class="form-group"> <label for="c-pid" class="control-label col-xs-12 col-sm-2">{:__('Venue_name')}:</label> <div class="col-xs-12 col-sm-8"> <select id="c-pid" data-rule="required" class="form-control selectpicker" name="row[v_id]"> {foreach name="venueList" item="vo"} <option value="{$vo.id}" {in name="key" value="0"}selected{/in}>{$vo.name}</option> {/foreach} </select> </div> </div>
編輯
<div class="form-group"> <label class="control-label col-xs-12 col-sm-2">{:__('Gid')}:</label> <div class="col-xs-12 col-sm-8"> <select id="c-gid" data-rule="required" class="form-control selectpicker" name="row[gid]"> {foreach name="photo_group" item="vo"} <option value="{$vo.id}" {in name="key" value="$row.id"}selected{/in}>{$vo.group_name}</option> {/foreach} </select> </div> </div>
lang
語言{:__('Venue_name')} ,在語言模板中找到新增即可
ajax請求後臺資料 並將資料寫入前端
api: {
bindevent: function (data, ret) {
$(document).on("change", "#c-type", function (e) {
var value = e.target.value;
$.ajax({
url: "appointmentorder/appointmentorder/re_appointment_list",
type: 'post',
dataType: 'json',
data: {value: value},
success: function (ret) {
console.log(ret);
var result = '';
for (var i=0; i< ret.length; i++) {
var item = ret[i];
result += "<option value="+ item.id +">" + item.name + " " + item.start_time +
"</option>";
};
$("#c-pid").empty().append(result);
$("#c-pid").selectpicker("refresh");
}, error: function (e) {
Backend.api.toastr.error(e.message);
}
});
});
Form.api.bindevent($("form[role=form]"));
}
}
前端下拉框顯示
<div class="form-group">
<label for="c-pid" class="control-label col-xs-12 col-sm-2">{:__('appointment_activity_list')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-pid" data-rule="required" class="form-control selectpicker" name="row[apt_id]">
{foreach name="appointment_activity_list" item="vo"}
<option value="{$key}" {in name="key" value="$row.apt_id"}selected{/in}>{$vo.name}.開館時間.{$vo.start_time}</option>
{/foreach}
</select>
</div>
</div>
後臺富文字欄位選text 開啟富文字外掛,,輸入命令生成curl
時間彈窗不能完全顯示
修改css
backend.css
.tab-addtabs {
/*overflow: hidden;*/
}
和
bootstrap.css和fastadmin.min.css增加
.content {
min-height: 250px;
padding: 15px;
margin-right: auto;
margin-left: auto;
padding-left: 15px;
padding-right: 15px;
padding-bottom:50px;
}
搜尋聯表處理
表 couponuser,coupon和user表
關聯欄位分別是c_id和user_id
對應的js
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Num_id')},
{field: 'coupon.name', title: __('couponuser_list')},
{field: 'user.nickname', title: __('user_name')},
{field: 'coupon', title: __('Coupon')},
{field: 'is_receivelist', title: __('Is_receivelist'),operate:false, visible:false, searchList: {"0":__('Is_receivelist 0'),"1":__('Is_receivelist 1')}},
{field: 'is_receivelist_text', title: __('Is_receivelist'), operate:false},
{field: 'is_use', title: __('Is_use'), visible:false, searchList: {"0":__('Is_use 0'),"1":__('Is_use 1')}},
{field: 'is_use_text', title: __('Is_use'), operate:false},
{field: 'imagesurl', title: __('Images'),operate:false, formatter: Table.api.formatter.images},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
model(在當期的model)
public function Coupon()
{
// return $this->hasOne('Coupon', 'id', 'c_id');
return $this->belongsTo('Coupon', 'c_id', 'id', [], 'LEFT')->field('name')->setEagerlyType(0);
}
public function User()
{
// return $this->hasOne('Coupon', 'id', 'c_id');
return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->field('nickname')->setEagerlyType(0);
}
控制器
/**
* 檢視
*/
public function index()
{
//設定過濾方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax()) {
//如果傳送的來源是Selectpage,則轉發到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->with(['coupon'])
->with(['user'])
->where($where)
// ->order($sort, $order)
->count();
$result = $this->model
->with(['coupon','user'])
->where($where)
->order('coupon_user.'.$sort, $order)
->limit($offset, $limit)
->select();
$result = collection($result)->toArray();
$host_url = "https://" . $_SERVER['HTTP_HOST'] . "/";
foreach ($result as $k => $v) {
$imagesurl = $host_url . $v['images'];
$result[$k]['imagesurl'] = $imagesurl;
$coupon = model('Coupon')->where('id', $v['c_id'])->select();
$coupon = collection($coupon)->toArray();
foreach ($coupon as $kk => $vv) {
$result[$k]['name'] = $vv['name'];
}
//獲取使用者名稱稱
$user_list = model('User')->where('id', $v['user_id'])->select();
$user_list = collection($user_list)->toArray();
foreach ($user_list as $key => $value) {
$result[$k]['nickname'] = $value['nickname'];
}
}
$result = array("total" => $total, "rows" => $result);
return $result;
// return json($result);
}
return $this->view->fetch();
}