Model
Model是专门和数据打交道的模块。
协程模式
model中可以调用redis,mysql,task的协程模式,但是请注意,如果model是使用协程的,那么controller或者model调用这个包含协程model接口时,也要加上yeild关键字。
例子:
public function http_testCoroutine()
{
$this->testModel = $this->loader->model('TestModel', $this);
$result = yield $this->testModel->test_coroutine();
$this->http_output->end($result);
}
Model层级
1.7.4版本支持深层级的Model。
$this->testModel = $this->loader->model('Test/TestModel', $this);
如上会调用Test目录下TestModel,请注意命名空间的规范。
在1.7.4版本之前需要这样
$this->testModel = $this->loader->model('Test\\TestModel', $this);