model文件
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\db\ActiveRecord;
class Folder extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'Folder';
}
public function search()
{
$query = Folder::find();
$folders = $query->where(['pid' => 0,'type'=>0])->all();
return $folders;
}
}
controller文件:
<?php
namespace app\controllers;
use Yii;
use app\controllers\CommonController;
use app\models\LoginForm;
use app\models\home\Folder;
class HomeController extends CommonController
{
public function actionIndex()
{
$model = new Folder();
$folders = $model->search();
return $this->render('index',[
'folders' => $folders,
]);
}
}
出现错误:
Unknown Class – yiibaseUnknownClassException
Unable to find 'appmodelshomeFolder' in file: /var/www/html/CodeNote/models/home/Folder.php. Namespace missing?
怎么处理???
appmodelshomeFolder;
你的文件是在这个路径下?
命名空间是否申明正确?
配置文件中修改链接参数