html:隐藏域
<input type="hidden" name="_csrf" value="<?php echo yii::$app->request->csrfToken?>">
<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
class IndexController extends Controller
{
//显示表单界面
public function actionIndex(){
return $this->renderPartial('index');
}
//执行添加
public function actionAdd(){
$connection = \Yii::$app->db;
$arr = \Yii::$app->request->post();
$connection->createCommand()->insert('ceshi',['title'=>$arr['title'],
'username'=>$arr['username'],
])->execute();
$this->redirect(array('/index/list'));
}
//查询数据库
public function actionList(){
$sql = "select * from ceshi";
$connection=\Yii::$app->db->createCommand($sql);
$arr=$connection->queryAll();
return $this->renderPartial('list',['arr'=>$arr]);
}
}
yii 原生语句 增删改查
最新推荐文章于 2023-07-31 14:54:50 发布