laravel框架从blade模板页面向php逻辑代码提交数据(传值)的位置是:从静态blade模板传值到模型(Models)或者传值到services或者传值到控制器
blade模板页面代码:
<form name="yzForm" id="yzForm" method="post" class="form-inline" action="/{{ Request::path() }}" target="_self" > <input type="hidden" name="_token" value=""> <fieldset> <div class="alert alert-block alert-warning"> @if ( $loginInfo['level'] === 1) <div class="row"> <div class="col-md-9"> {{--时间from到to--}} <div class="form-group"> <input class="form-control input-sm" name="create_start" id="create_start" type="text" placeholder="开始" value="{{ $args['create_start'] }}" οnclick="WdatePicker({dateFmt: 'yyyy-MM-dd'})" readonly > </div> ~ <div class="form-group"> <input class="form-control input-sm" name="create_end" id="create_end" type="text" placeholder="结束" value="{{ $args['create_end'] }}" οnclick="WdatePicker({dateFmt: 'yyyy-MM-dd'})" readonly> </div> {{--操作人--}} <div class="form-group"> <select class="form-control input-sm" name="name" id="name" itemname='操作人'> <option value="">操作人A</option> <option value="{{ $args['name'] }}" <?=$searchType == 'mb_id' ? 'selected':'';?>>用户</option> </select> </div> {{--员工编号--}} <div class="form-group"> <input class="form-control input-sm" name="emp_id" id="emp_id" type="text" placeholder="员工编号" value="{{ $args['emp_id'] }}"> </div> {{--操作内容--}} <div class="form-group"> <input class="form-control input-sm" name="log_content" id="log_content" type="text" placeholder="操作的内容" value="{{ $args['log_content'] }}" > </div> {{--查询--}} <div class="form-group"> <button type="submit" name="search" class="btn btn-default btn-sm">查询</button> </div> {{--定位导出--}}{{-- <div class="form-group"> <input type="submit" value="导出" name="output" class="btn btn-default btn-sm"><span style="color: red;line-height: 33px;"> * 导出时至少带有一个条件</span> </div> --}}{{--刷新--}}{{-- <div class="form-group"> <button type="button" class="btn btn-default btn-sm" οnclick="" rel="tooltip" data-placement="bottom" data-original-title="刷新"><i class="fa fa-refresh"></i></button> </div>--}} </div><!--col-md-9:e--> <div class="col-md-3"> <div class="form-group pull-right"> <label class="">Page</label> <select class="form-control input-sm" name="pageSize" id="pageSize" itemname='리밋트' οnchange="javascript:document.yzForm.submit(this);"> <option value="{{$log->perPage()}}" <?=$pageSize == $log->perPage() ? 'selected':'';?> style="display: none">{{$log->perPage()}}</option> <option value="20" <?=$pageSize == '20' ? 'selected':'';?>>20</option> <option value="30" <?=$pageSize == '30' ? 'selected':'';?>>30</option> <option value="50" <?=$pageSize == '50' ? 'selected':'';?>>50</option> <option value="100" <?=$pageSize == '100' ? 'selected':'';?>>100</option> </select> </div> </div><!--col-md-3:e--> </div><!--search row:e--> @endif </div> <!-- table-responsive start --> <div class="table-responsive"> <table class="table table-striped table-bordered table-hover"> <thead> <th>操作人</th> <th>员工编号</th> <th>操作类型</th> <th>相关表</th> <th>操作资源ID</th> <th>操作内容</th> <th>操作时间</th> </thead> <tbody> @if(COUNT($log) > 0 ) @foreach ($log as $key => $value) <tr> <td>{{ $value->name }}</td> <td >{{ $value->emp_id }}</td> <td >{{ $value->log_type }}</td> <td >{{ $value->log_table }}</td> <td >{{ $value->log_dataid }}</td> <td >{{ $value->log_content }}</td> <td> @if( $value->log_create) {{ date('Y-m-d H:i:s', $value->log_create) }} @endif </td> </tr> @endforeach @else <tr> <td colspan="7"><p class="hcolor" style="line-height: 60px;text-align:center;clear:both;"> 暂无相关数据 </p> </td> </tr> @endif </tbody> {{--下面的合并框--}} <tfoot> <tr> <td colspan="6"> {{--导出--}} <div class="form-group" style="position: relative;"> <input type="submit" value="导出" name="output" class="btn btn-default btn-sm"><span style="color: red;line-height: 33px;"> * 导出时至少带有一个条件</span> </div> </td> <td colspan="1"> @if($log->total() > 0) <div class="well well-sm result_data"> <dl> <dt>日志总数</dt> <dd>{{ number_format($log->total()) }} 条</dd> </dl> <dl> <dt>当前页码</dt> <dd>{{ number_format($log->currentPage()) }} 页</dd> </dl> </div> @endif </td> </tr> </tfoot> </table> <span class='pagination pull-right'> @if($log->total() > 0) {!! $log->appends($args)->render() !!} @endif </span> </div> </fieldset> </form>
systemservices.php页面代码:
/** * 操作日志列表 */ public static function log(&$request) { $_db = DB::table('logs') ->leftJoin('admin','logs.emp_id','=','admin.user_id'); //操作时间 if($request['create_start']) { $start_time = strtotime($request['create_start']); $_db = $_db->where('logs.log_create', '>=', $start_time); } if($request['create_end']) { $end_time = strtotime($request['create_end']. ' 23:59:59'); $_db = $_db->where('logs.log_create', '<=',$end_time); } //操作人 if($request['name']) { $_db = $_db->where('admin.name', 'like', '%'.$request['name'].'%'); } //用户编号 if($request['emp_id']) { $_db = $_db->where('logs.emp_id', '=', $request['emp_id']); } //操作内容 if($request['log_content']) { $_db = $_db->where('logs.log_content', 'like', '%'.$request['log_content'].'%'); } $data = $_db->orderBy('log_create','desc') ->select( 'admin.name', 'logs.emp_id', 'logs.log_type', 'logs.log_table', 'logs.log_dataid', 'logs.log_content', 'logs.log_create' ) ->paginate(max($request['pageSize'],20)); //dd($data); //dd($data->perPage());//获取每页显示的条数 return $data; }
systemcontroller.php页面代码
public function log() { //var_dump(Request::all()); if($this->_request['output']) { if($this->_request['create_start'] || $this->_request['create_end'] || $this->_request['name'] || $this->_request['emp_id'] || $this->_request['log_content']) { $tsv = array(); $tsv['title'] = array("操作人","员工编号","操作类型","相关表","region","操作内容","操作时间"); $tsv['filename'] = "操作日志"; $tsv['content'] = array(); $result = SystemService::excel($this->_request); $data = object_array($result); //对象转数组 $tmp = array(); foreach ($data as $item){ $tmp[] = $item['name']; $tmp[] = $item['emp_id']; $tmp[] = $item['log_type']; $tmp[] = $item['log_table']; $tmp[] = $item['log_dataid']; $tmp[] = $item['log_content']; $tmp[] = date('Y-m-d H:i:s', $item['log_create']); $tsv['content'][] = $tmp; $tmp = array(); } if (exportToExcel($tsv)){ return true; } }else { return redirect('/System/log'); } } else { $data = SystemService::log($this->_request); View::share('log',$data); //dd($data->perPage()); return $this->display('admin.system.log'); } }可以看出从blade模板向两个代码页面都有传值情况