1.model 书写: 注意:class后和文件名相同且大写,引入Model和Db类操作数据库
<?php
namespace app\index\model;
use think\Model;
use think\Db;
class Tphui extends Model
{
public function query()
{
$data = Db::table('tphui_art') -> select();
return $data;
}
}
2.Controller层:引入model文件;new 实例对象 $tphui = new Tphui();
<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\Tphui;
class Index extends Controller
{
public function index()
{
// 模板变量赋值-测试
$this -> assign('ss','ssss');
$this -> assign([
'name' => 'tp5',
'tel' => '13588000'
]);
$tphui = new Tphui();
// return 'index/sss';
$data = $tphui->query();
$