第一步:sql注意:id要自增,怎么做才能自增呢?
models:记住,继承了ActiveRecord后,就得到了它所有的功能哦(注意,sql表要跟models相对应!!!)
<?php
namespace frontend\models;
use yii\db\ActiveRecord;
class Article extends ActiveRecord
{
}
控制器:注意,一个一个的来哦
<?php
namespace frontend\controllers;
use frontend\models\Article;
class IndexController extends \yii\web\Controller
{
public function actionIndex()
{//增加
/*$article=new Article();
$article->title="cyg";
$article->created_at=time();
$article->save();*/
//修改
/*$article=Article::findOne(['id'=>1]);
$article->title="lwien";
$article->save();*/
//删除
$article=Article::findOne(['id'=>1]);
$article->delete();
}}