标签:
1. 使用ActiveField中的hint生成提示文字
<?= $form->field($model, ‘freightAddedFee‘)->textInput()->hint(‘大于0的整数‘) ?>
2. 文本框内 placeholder,其实这个本来就是html5带的属性。
<?= $form->field($model, ‘mobile‘, $input_class)->textInput([‘maxlength‘ => 60,‘placeholder‘ => ‘11位数字‘]) ?>
1. 通过中间表关联查询
public function getVendorNickName(){
return $this->hasOne(User::className(), [‘id‘ => ‘userId‘])
->viaTable(BaseVendor::tableName(), [‘id‘ => ‘vendorId‘]);
}
参见:http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#relations-with-junction-table
2. 查询语句使用join时为表起别名。起别名可以防止冲突,因为有时候会join一张表两次。
下面的例子为user表起了u1的别名
$query->joinWith([‘vendorNickName‘ => function ($q) { $q->where(‘u1.nickname LIKE "%‘ . $this->vendorNickName . ‘%"‘) ->from(User::tableName().‘ u1‘); }]);
生成的SQL类似:
SELECT `za_order`.* FROM `za_order` LEFT JOIN `za_user_vendor` ON `za_order`.`vendorId` = `za_user_vendor`.`id` LEFT JOIN `za_user` `u1` ON `za_user_vendor`.`userId` = `u1`.`id` WHERE u1.nickname LIKE "%一号微店%"
标签:
原文地址:http://www.cnblogs.com/mafeifan/p/4205527.html