public function rules(){ return [ ['title','required','message'=>'标题不能为空'], ['title','string','min'=>2,'max'=>200,'tooShort'=>'标题不能少于两位','tooLong'=>'标题不能大于200位'], ['content','required','message'=>'内容不能为空'], ['description','string','max'=…
方法一:(使用model) $modelCommunityMail = CommunityMail::find()->where(['com_id'=>$id])->all(); 方法二:(直接拼写sql语句) $sql = "select * from `usho_community_mail` where date_format(`created_at`,'%Y%m') = date_format(curdate() ,'%Y%m') AND `com_id`=$id AN…
  一. [:id占位符]使用 $results = Test::findBySql($sql,array(':id'=>'1 or 1=1))->all()   二. [id=1]  选出id为1的数据 $results = Test::find()->where(['id'=>1])-all(); 三.  [id>0]  选出id>0的数据 $results = Test::find()->where(['>','id',0])->all() 四.…
1.model中models/article.php 1 <?php 2 3 namespace app\models; 4 5 use Yii; 6 7 /** 8 * This is the model class for table "yii2_article". 9 * 10 * @property string $id 11 * @property integer $category_id 12 * @property string $title 13 * @prope…
第一次使用,时候不明白什么原理,大概用了几次后,才模模糊糊搞清楚原来是怎么一回事,现在就把写过的代码,贴在下边. 1.在视图文件中, 第一步首先在index.php文件中 做了一个a链接的按钮 调用了modal <a class="btn btn-default pull-right" data-remote="<?= Url::toRoute(['create', '_wicket' => 'yes']) ?>" data-toggle=&…
1.Model中Code.php <?php /** * Created by PhpStorm. * User: moka同学 * Date: 2016/07/25 * Time: 10:48 */ namespace app\models; use yii\base\Model; class Code extends Model{ public $verifyCode; public function rules() { return [ ['verifyCode','captcha','c…
1.创建model   /biaodan.php <?php /** * Created by PhpStorm. * User: moka同学 * Date: 2016/08/05 * Time: 10:26 */ namespace app\models; use Yii; use yii\base\Model; class Biaodan extends Model{ public $name; public $pass; public $email; public $sex; publi…
1.控制器中CacheDemoController.php <?php /** * Created by PhpStorm. * User: moka同学 * Date: 2016/06/29 * Time: 8:38 */ namespace app\controllers; use yii\web\Controller; class CacheDemoController extends Controller { /* public function behaviors() { return…
匿名函数设置$value <?= GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ // ['class' => 'yii\grid\SerialColumn'], 取消掉编号 ['attribute'=>'id', 'contentOptions'=>['width'=>'30'], ], 'code', // 'name', [ 'attribute'=>'name',…
1.model中建立关联 public function getUser(){ return$this->hasOne(User::className(),['id'=>'uid']) ; } 2.在视图中 <?= GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ // ['class' => 'yii\grid\SerialColumn'], 取消掉编号 ['attribute'=&g…