1.yii\basic\config\db.php 修改数据库配置(dbname,username,password),新建数据库test
2.basic\models目录下新建Users.php
[code]
<?php
namespace app\models;
use yii\db\ActiveRecord;
class Users extends ActiveRecord
{
}
?>
[/code]
3.basic\controllers add UsersController.php
[code]
<?php
namespace app\controllers;
use yii\web\Controller;
use app\models\Users;
class UsersController extends Controller
{
public function actionIndex()
{
$users = Users::find()->all();
//print_r($users);
return $this->render('index',['users'=>$users]);
}
}
?>
[/code]
4.basic\views\ 下增加一个文件夹Users,里面新建一个页面index.php,页面打印参数users
[code]<?php
foreach($users as $item){
echo $item->username."<br>";
}
?>[/code]