Test.php
<?
namespace app\models;
use yii\db\ActiveRecord;
class Test extends ActiveRecord
{
public static function tableName(){
return "test";
}
}
IndexController.php
<?php
namespace app\controllers;
use yii\web\Controller;
use app\models\Test;
class IndexController extends Controller
{
public function actionIndex()
{
$model = new Test();
$data = $model->find()->one();
return $this->render("index",array("row"=>$data));
}
}
为什么$model = new Test();报错
Unknown Class – yii\base\UnknownClassException
Unable to find 'app\models\Test' in file: D:\phpStudy\PHPTutorial\WWW\bs/models/Test.php. Namespace missing?
Test.php文件的开始应该是
<?php
namespace app\models;
….
你少写了php吧,短标记已经不适用,在apache默认不启用,除非你自己将它开启。
PHP标记
找不到类啊,看看命名空间
在你的IndexController控制上写
namesapce app\controllers;
…
use app\controllers\Test;
试试
不需要new
这么写就可以