class Jijiajian extends Base
{
public function jijiajianList()
{
$jijiajianList = JijiajianModel::all();
$count = JijiajianModel::count();
foreach ($jijiajianList as $value){
$data = [
'id' => $value->id,
'xuhao' => $value->xuhao,
'tuhao' => $value->tuhao,
'name' => $value->name,
'shuliang' => $value->shuliang,
'danzhong' => $value->danzhong,
'cailiao' => $value->cailiao,
'leibie' => $value->leibie,
'guige' => $value->guige,
'leibie2' => $value->leibie2,
'beizhu' => $value->beizhu,
'luruyuan' => $value->luruyuan,
'lururiqi' => $value->lururiqi,
'status' => $value->status,
'create_time' => $value->create_time,
'gongyika' => isset($value->gongyika->tuhao)? $value->gongyika->tuhao : '<span style="color:red;">未分配</span>',
];
$jijiajianList[] = $data;
}
$this -> view -> assign('jijiajianList', $jijiajianList);
$this -> view -> assign('count', $count);
return $this -> view -> fetch('jijiajian');
}
<?php
namespace app\index\model;
use think\Model;
use traits\model\SoftDelete;
class Jijiajian extends Model
{
//引用软删除方法集
use SoftDelete;
//设置当前表默认日期时间显示格式
protected $dateFormat = 'Y/m/d';
//定义表中的删除时间字段,来记录删除时间
protected $deleteTime = 'delete_time';
// 开启自动写入时间戳
protected $autoWriteTimestamp = true;
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
// 定义自动完成的属性
protected $insert = ['status' => 1];
public function gongyika()
{
return $this->belongsTo('gongyika');
}
// 定义关联方法
/* public function student()
{
return $this->hasMany('student');
}*/
}
请问老师,上述代码,机加件表里的数据咋显示不出来呢,$count=0,数据获取不到,同样的代码,另外一个表就没事
<?php
namespace app\index\model;
use think\Model;
use traits\model\SoftDelete;
class Gongyika extends Model
{
//引用软删除方法集
use SoftDelete;
//设置当前表默认日期时间显示格式
protected $dateFormat = 'Y/m/d';
//定义表中的删除时间字段,来记录删除时间
protected $deleteTime = 'delete_time';
// 开启自动写入时间戳
protected $autoWriteTimestamp = true;
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $type = [
'start_time'=>'timestamp',
];
public function jijiajian()
{
// 班级表与教师表是1对1关联
return $this->hasOne('jijiajian');
}
}
<?php
namespace app\index\controller;
use app\index\model\Gongyika as GongyikaModel;
use app\index\model\Jijiajian;
use think\Request;
class Gongyika extends Base
{
public function gongyikaList()
{
$gongyikaList = GongyikaModel::all();
//$gongyikaList =GongyikaModel::select();
//获取记录数量
$count = GongyikaModel::count();
//
foreach ($gongyikaList as $value){
$data = [
'id' => $value->id, //主键
'chanpinxinghao' => $value->chanpinxinghao, //产品型号
'chanpinname' => $value->chanpinname, //产品名称
'tuhao' => $value->tuhao, //零件图号
'lingjianname' => $value->lingjianname, //零件名称
'cailiao' => $value->cailiao, //材质
'maopizhonglei' => $value->maopizhonglei, //毛坯种类
'pihao' => $value->pihao, //每件毛坯制作件数
'meitaijianshu' => $value->meitaijianshu, //每台件数
'gongxuhao' => $value->gongxuhao, //工序号
'gongxuname' => $value->gongxuname, //工序名称
'gongbuhao' => $value->gongbuhao, //工步号
'gongxuneirong' => $value->gongxuneirong, //工序内容
'sel1' => $value->sel1, //设备型号
'sel2' => $value->sel2, //刀具型号
'zhunbeigongshi' => $value->zhunbeigongshi, //准备工时
'danjiangongshi' => $value->danjiangongshi, //单件工时
'create_time' => $value->create_time,
'status' => $value->status, //当前启用状态
'jijiajian' => isset($value->jijiajian->tuhao)? $value->jijiajian->tuhao : '<span style="color:red;">未分配</span>',
];
//每次关联查询结果,保存到数组 $teacher中
$gongyikaList[] = $data;
}
$this -> view -> assign('gongyikaList', $gongyikaList);
$this -> view -> assign('count', $count);
//设置当前页面的seo模板变量
return $this -> view -> fetch('shebei1');
}
谢谢朱老师,这个问题已经解决了,少了句隐藏域代码已经修改完毕并成功运行
请将出错的提示信息一并提供