代码如下(模型文件):
<?php
namespace app\index\model;
use think\Model;
class PublicUsers extends Model
{
public function factory()
{
return $this->hasOne('PublicFactorys','id','factoryid');
}
public function partment()
{
// 用户HAS ONE档案关联
return $this->hasOne('PublicPartments','id','partmentid');
}
public function author()
{
// 用户HAS ONE档案关联
return $this->hasOne('PublicAuthors','id','authorid');
}
public function role()
{
// 用户HAS ONE档案关联
return $this->hasOne('PublicRoles','id','roleid');
}
public function fileauthor()
{
// 用户HAS ONE档案关联
return $this->hasOne('FileFileAuthors','id','fileauthorid');
}
public function specialty()
{
// 用户HAS ONE档案关联
return $this->hasOne('PublicSpecialtys','id','specialtyid');
}
}
控制器文件:
<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Cookie;
use think\Session;
use think\Url;
use think\Request;
use app\index\model\PublicUsers;
class Login extends Controller
{
function __construct()
{
parent::__construct();
}
public function index()
{
$param = $this->request->param();
if(!empty($param)){
$logname = trim($param['logname']);
$password = md5(trim($param['password']));
$list = PublicUsers::where(['logname'=>$logname,'password'=>$password])->find();
if(!empty($list)){
echo $list['factory']['factoryname'];
}
}
}
}
最佳答案
