yii 之增加数据

mac2022-06-30  24

模型代码:

<?php namespace app\models; use yii\db\ActiveRecord; class Test extends ActiveRecord{ public function rules() { return [ ['title','string','length'=>[0,10]] ]; } }

 

 

控制器代码:

public function actionTest(){ //添加数据 $test = new Test; $test->title = ''; $test->validate(); if ($test->hasErrors()) { echo 'error'; } else { $test->save(); } }

 

结论:保存数据及验证数据。

转载于:https://www.cnblogs.com/gyfluck/p/9101273.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)