<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
class DemoController extends Controller{
public $enableCsrfValidation = false;
public function actionIndex(){
return $this->render("index");
}
public function actionAdd()
{
$name = Yii::$app->request->post('name');
$res=Yii::$app->db->createCommand("insert into diyi(`name`) value('$name')")->execute();
return $this->redirect(['demo/show']);
}
public function actionShow()
{
header("content-type:text/html;charset=utf-8");
$data = Yii::$app->db->createCommand("select * from `diyi`")->queryAll();
return $this ->render('show',['data'=>$data]);
}
public function actionDel()
{
$id = Yii::$app->request->get('id');
$del = Yii::$app->db->createCommand("delete from diyi where id = '$id'")->execute();
return $this->redirect(['demo/show']);
}
public function actionFind()
{
$id = Yii::$app->request->get('id');
$data = Yii::$app->db->createCommand("select * from diyi where id = '$id'")->queryAll();
$res=$data[0];
return $this->render('find',['res'=>$res]);
}
}
namespace app\controllers;
use Yii;
use yii\web\Controller;
class DemoController extends Controller{
public $enableCsrfValidation = false;
public function actionIndex(){
return $this->render("index");
}
public function actionAdd()
{
$name = Yii::$app->request->post('name');
$res=Yii::$app->db->createCommand("insert into diyi(`name`) value('$name')")->execute();
return $this->redirect(['demo/show']);
}
public function actionShow()
{
header("content-type:text/html;charset=utf-8");
$data = Yii::$app->db->createCommand("select * from `diyi`")->queryAll();
return $this ->render('show',['data'=>$data]);
}
public function actionDel()
{
$id = Yii::$app->request->get('id');
$del = Yii::$app->db->createCommand("delete from diyi where id = '$id'")->execute();
return $this->redirect(['demo/show']);
}
public function actionFind()
{
$id = Yii::$app->request->get('id');
$data = Yii::$app->db->createCommand("select * from diyi where id = '$id'")->queryAll();
$res=$data[0];
return $this->render('find',['res'=>$res]);
}
}