重新提问下,获取parent_id测试总是0
来源:5-5 编辑功能开发

慕粉0958041534
2017-05-01
问题在于后台获取
$parentId = input('get.parent_id', 0 ,'intval'); if (!$parentId) { print_r($parentId); }
这样测试,输出是这样的
检查了很多次,以前用tp时也没有遇到过,看我在本课程的学习时间就知道我调这个bug调了多久了,老师务必回答下,是否是前台获取parent_id时候出错?后台print_r出来的parent_id,或者是Bis那一节前台能输出的city和Category都是parent_id=0的情况
附上sql语句输出情况。
model层
<?php namespace app\Common\Model; use think\model; class Category extends Model { //开启自动写入时间戳 protected $autoWriteTimesTamp = true; public function add($data){ $data['status'] = 1; //$data['create_time'] = time(); return $this->save($data); } public function getNormalFirstCategory() { $data = [ 'status' => 1, 'parent_id' => 0, ]; $order = [ 'id' => 'desc', ]; //echo $this->getLastSql(); return $this->where($data) ->order($order) ->select(); } public function getFirstCategory( $parentId = 0) { $data = [ 'parent_id' => $parentId, 'status' => ['neq', -1], ]; $order = [ 'id' => 'desc', ]; $result = $this->where($data) ->order($order) ->paginate(3); echo $this->getLastSql(); return $result; } public function getNormalCagegoryByParentId( $parentId = 0) { $data = [ 'status' => 1, 'parent_id' => $parentId, ]; $order = [ 'id' => 'desc', ]; //echo $this->getLastSql(); return $this->where($data) ->order($order) ->select(); } }
Controller
class Category extends Controller { private $Category; public function _initialize() { $this->Category = model("Category"); } public function index() { Request::instance()->has('parent_id','get'); $parentId = input('get.parent_id', 0 ,'intval'); if (!$parentId) { print_r($parentId); echo "-----------"; } $categorys = $this->Category->getFirstCategory($parentId); //print_r($this->Category->getFirstCategory()); return view('', [ 'categorys' => $categorys, ]); }
前端模块
<!--包含头部文件--> {include file="public/header" /} <body> <nav class="breadcrumb"><i class="Hui-iconfont"></i> 首页 <span class="c-gray en">></span> 分类管理 <span class="c-gray en">></span> 分类列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont"></i></a></nav> <div class="page-container"> <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"> <a class="btn btn-primary radius" onclick="o2o_s_edit('添加生活服务分类','{:url('category/add')}','','300')" href="javascript:;"><i class="Hui-iconfont"></i> 添加分类</a></span> <span class="r"></span> </div> <img style="margin:20px" width="280" height="140" src="http://api.map.baidu.com/staticimage/v2?ak=CIgFiPGvgq92PuPGm2K3Xqk7HMpWRSxb&width=280&height=140&zoom=10" /> <img style="margin:20px" width="280" height="140" src="{:url('index/map')}" /> <div class="mt-20"> <table class="table table-border table-bordered table-bg table-hover table-sort"> <thead> <tr class="text-c"> <th width="40"><input name="" type="checkbox" value=""></th> <th width="80">ID</th> <th width="100">分类</th> <th width="30">排序序号</th> <th width="150">新增时间</th> <th width="60">发布状态</th> <th width="100">操作</th> </tr> </thead> <tbody> {volist name = "categorys" id = "vo"} <tr class="text-c"> <td><input name="" type="checkbox" value=""></td> <td>{$vo.id}</td> <td>{$vo.name}</td> <td class="text-c">{$vo.listorder}</td> <td>{$vo.create_time}</td> <td class="td-status"><a href="" title="点击修改状态">{$vo.status|getStatus}</a></td> <td class="td-manage"><a href="{:url('category/index',array('parent_id'=>$vo.id))}">获取子栏目</a><a style="text-decoration:none" class="ml-5" onClick="o2o_s_edit('编辑','{:url('category/edit', ['id'=>$vo.id])}','',300)" href="javascript:;" title="编辑"><i class="Hui-iconfont"></i></a> <a style="text-decoration:none" class="ml-5" onClick="o2o_del('','')" href="javascript:;" title="删除"><i class="Hui-iconfont"></i></a></td> </tr> {/volist} </tbody> </table> </div> </div> <div class="cl pd-5 bg-1 bk-gray mt-20">{$categorys->render()}</div> <!--包含头部文件--> {include file="public/footer" /}
写回答
3回答
-
singwa
2017-05-01
你跑送的http地址多少?如果是纯pathinfo模式的 话,可以使用 params()方法来获取
012017-05-02 -
singwa
2017-05-01
加我扣扣交流
012017-05-01 -
singwa
2017-05-01
你的地址多少
00
相似问题