首页 > thinkphp common model 怎么使用?

thinkphp common model 怎么使用?

目前使用的是 /模块/Model/xxxModel.class.php 文件的内容
我想要通过 /Common/Model/ 来简历一个 Model 怎么操作?
我试过把 模块 Model 直接迁移到 Common Model 目录下,并且修改了 namespace,不过还是无效。

那么正确的办法是怎么样的?


你看看这样行不行

common model

<?php
namespace Common\Model;
use Think\Model;

class TestModel extends Model{
    ...
}

控制器调用

namespace Index\Controller;

use Think\Controller;
use Common\Model\TestModel;

class IndexController extends Controller
{
    public function index()
    {
        $m = new TestModel();
    }
}

更改你的代码

namespace Home\Controller;
use Think\Controller;
use Common\Model\TestUnderModel;

class IndexController extends Controller {
    public function index() {
        $model_test = D('TestUnder');
        $model_test->sayHi();
    }
}

这是完全可以运行的

【热门文章】
【热门文章】