php - yii2怎么连接数据库操作
黄舟
黄舟 2017-04-11 09:00:07
0
3
704

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?
怎么处理???

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(3)
Peter_Zhu
use app\models\home\Folder;
//修改为 use app\models\Folder;
命名空间写错了
黄舟

appmodelshomeFolder;

你的文件是在这个路径下?

命名空间是否申明正确?

阿神

配置文件中修改链接参数

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template