(1)use yii\bootstrap\ActiveForm; 请求form表单
'', 'action' => "提交地址" . $model->id]); ?> field($order, '已实例化的字段', [ 'inputOptions' => ['class' => '', 'placeholder' => '', 'tabindex' => ''], 'template' => '{input}{error} '])->textInput(); radioList(['0' => '冻结', '1' => '正常']); textarea();?>
(2)use yii\data\Pagination;请求分页
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);$model = $data->offset($pages->offset) ->limit($pages->limit) ->orderBy('id asc') ->asArray()->all(); $pages]); ?>
(3)foreach循环
$val) { ?>
(4)$this->render(,['']) 渲染页面 $this->redirect(['']); 重定向
(5)实例化对象
$model = Models::find(); $model = Models::findOne(' '=>' ',' '=>' '); $model = $id ? Models::findOne($id) : new Models();
(6)类的公用函数指定布局
public $layout = 'view';(7)查询条件
where([' '=>' ',' '=>' '])查询条件select(' ')查询字段asArray( )查询结果作为数组
(8)控制器接收数据
$model->load(Yii::$app->request->post()) && $model->validate()$params = Yii::$app->request->post();$params = Yii::$app->request->get();
(9)函数
$newfield = explode(',', $abc); 把字符串按照参数分割为数组number_format(number,decimals,decimalpoint,separator) 函数通过千位分组来格式化数字。bcadd()bcsub()
(10)ajax传参数json
use yii\web\Response;public function init() init初始化的成员函数使用{parent::init();if (Yii::$app->request->isAjax)Yii::$app->response->format = Response::FORMAT_JSON;}return ['msg'=>'提示信息'];
(11)保存数据
$_model->save();(12)引入文件
$this->registerCssFile('相对地址', ['depends' => 'yii\web\YiiAsset', 'position' => 1]);$this->registerJsFile('相对地址', ['depends' => 'yii\web\YiiAsset', 'position' => 1]);
(13)用户是否登录
if (\Yii::$app->user->isGuest) {return $this->redirect('/');} $id = Yii::$app->user->getIdentity()->id; 获取当前用户的id
(14)联查
$record = 表一::find()->innerJoin(表二, $order_table . ".online_pid=" . $product_table . ".id")->select($order_table . ".*," . $product_table . ".title as abc,"" . $product_table . '.money,' . $product_table . '.yield_rate,' . $product_table . '.refund_method,' . $product_table . '.expires,' . $product_table . '.start_date,' . $product_table . '.end_date')$sql = $record->createCommand()->getRawSql();$model = $db->createCommand($sql)->queryAll();
(15)报错
$model->addError('字段', '提示');(16)事物
$transaction = Yii::$app->db->beginTransaction();$transaction->commit();$transaction->rollBack();
(17)隐藏域
field($omodel, 'order_money', ['template' => '{input}'])->hiddenInput() ?> order_money ?>" name="order_money"/> field($omodel, 'order_money', ['template' => '{error}']) ?>