项目场景:
提示:这里简述项目相关背景:
例如:项目场景:YII2模型查询
问题描述
提示:这里描述项目中遇到的问题:
例如:YII2模型查询 报错
Call to undefined method app\models\test::find()
模型代码
<?php
namespace app\models;
use yii\base\Model;
class Test extends Model
{
/**定义表名
* @return string
*/
public static function tableName(){
return 'test';//表名字
}
}
控制器
<?php
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\Response;
use app\models\Tset;
class TestController extends Controller
{
/**
* Displays
*
* @return string
*/
public function actionTest()
{
$list = Test::find()->all();
}
}
# 解决方案:
模型不要继承Model改为继承\yii\db\ActiveRecord即可
```c
模型代码
<?php
namespace app\models;
use yii\base\Model;
class Test extends \yii\db\ActiveRecord
{
/**定义表名
* @return string
*/
public static function tableName(){
return 'test';//表名字
}
}