1. ?? ??
? ???? ? ?? ??? ?????. ?? ???? ???? ?? ???? gii? ??? ? ???, ???? ?? ?? ????. ? ??? ?? ?? ???? ?? ??? ???? ??????. ?? ??? ???? ????.
1. ?? ??? ??
<?php //...other code //關(guān)聯(lián) public function getCate(){ return $this->hasOne(ArticleCate::className(),['id' => 'cid']); } ?>
2. ?? ??
common/models/search/Create ArticleSearch.php
<?php namespace common\models\search; use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; use common\models\Article; class ArticleSearch extends Article { //public $cname;//文章類別名 /** * @inheritdoc */ public function rules() { return [ [['cid','created_at', 'updated_at'], 'integer'], [['id', 'desc','title','cover','content'], 'safe'], ]; } /** * @inheritdoc */ public function scenarios() { // bypass scenarios() implementation in the parent class return Model::scenarios(); } //搜索 public function search($params) { $query = Article::find(); // $query->joinWith(['cate']);//關(guān)聯(lián)文章類別表 // $query->joinWith(['author' => function($query) { $query->from(['author' => 'users']); }]); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => 2, ], ]); // 從參數(shù)的數(shù)據(jù)中加載過濾條件,并驗證 $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } // 增加過濾條件來調(diào)整查詢對象 $query->andFilterWhere([ // 'cname' => $this->cate.cname, 'title' => $this->title, ]); $query->andFilterWhere(['like', 'title', $this->title]); //$query->andFilterWhere(['like', 'cate.cname', $this->cname]) ; return $dataProvider; } }
2. ??? ??
?? 1
?? ????? ???? ??? ??? ???? ????. with data :
<?php //other code use yii\data\Pagination; public function actionArticlelist() { //分頁讀取類別數(shù)據(jù) $model = Article::find()->with('cate'); $pagination = new Pagination([ 'defaultPageSize' => 3, 'totalCount' => $model->count(), ]); $model = $model->orderBy('id ASC') ->offset($pagination->offset) ->limit($pagination->limit) ->all(); return $this->render('index', [ 'model' => $model, 'pagination' => $pagination, ]); } ?>
??, ??? ???? ???? ?? ????? ??? ??? ?? ???? ?????.
<?php use yii\widgets\LinkPager; use yii\helpers\Html; use yii\helpers\Url; //other code foreach ($models as $model) { // 在這里顯示 $model } // 顯示分頁 echo LinkPager::widget([ 'pagination' => $pagination, 'firstPageLabel'=>"First", 'prevPageLabel'=>'Prev', 'nextPageLabel'=>'Next', 'lastPageLabel'=>'Last', ]); ?>
?? 2
????:
<?php $query = Article::find()->with('cate'); $provider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => 3, ], 'sort' => [ 'defaultOrder' => [ //'created_at' => SORT_DESC, //'title' => SORT_ASC, ] ], ]); return $this->render('index', [ 'model' => $query, 'dataProvider' => $provider ]); ?>
??:
<?php use yii\grid\GridView; echo GridView::widget([ 'dataProvider' => $dataProvider, //每列都有搜索框 控制器傳過來$searchModel = new ArticleSearch(); //'filterModel' => $searchModel, 'layout'=> '{items}<div class="text-right tooltip-demo">{pager}</div>', 'pager'=>[ //'options'=>['class'=>'hidden']//關(guān)閉自帶分頁 'firstPageLabel'=>"First", 'prevPageLabel'=>'Prev', 'nextPageLabel'=>'Next', 'lastPageLabel'=>'Last', ], 'columns' => [ //['class' => 'yii\grid\SerialColumn'],//序列號從1開始 // 數(shù)據(jù)提供者中所含數(shù)據(jù)所定義的簡單的列 // 使用的是模型的列的數(shù)據(jù) 'id', 'username', ['label'=>'文章類別', /*'attribute' => 'cid',產(chǎn)生一個a標簽,點擊可排序*/ 'value' => 'cate.cname' ], ['label'=>'發(fā)布日期','format' => ['date', 'php:Y-m-d'],'value' => 'created_at'], // 更復(fù)雜的列數(shù)據(jù) ['label'=>'封面圖','format'=>'raw','value'=>function($m){ return Html::img($m->cover,['class' => 'img-circle','width' => 30]); }], [ 'class' => 'yii\grid\DataColumn', //由于是默認類型,可以省略 'value' => function ($data) { return $data->name; // 如果是數(shù)組數(shù)據(jù)則為 $data['name'] ,例如,使用 SqlDataProvider 的情形。 }, ], [ 'class' => 'yii\grid\ActionColumn', 'header' => '操作', 'template' => '{delete} {update}',//只需要展示刪除和更新 /*'headerOptions' => ['width' => '80'],*/ 'buttons' => [ 'delete' => function($url, $model, $key){ return Html::a('<i class="glyphicon glyphicon-trash"></i> 刪除', ['artdel', 'id' => $key], ['class' => 'btn btn-default btn-xs', 'data' => ['confirm' => '你確定要刪除文章嗎?',] ]); }, 'update' => function($url, $model, $key){ return Html::a('<i class="fa fa-file"></i> 更新', ['artedit', 'id' => $key], ['class' => 'btn btn-default btn-xs']); }, ], ], ], ]); ?>
3. ??? ???? ??
?? ?? ??(??? ???)
?? ??? ??
?? ?? ???? ??:
<?php public function actionIndex() { $searchModel = new ArticleSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } ?>
??:
<?php $form = ActiveForm::begin([ 'action' => ['index'], 'method' => 'get', 'id' => 'cateadd-form', 'options' => ['class' => 'form-horizontal'], ]); ?> <?= $form->field($searchModel, 'title',[ 'options'=>['class'=>''], 'inputOptions' => ['placeholder' => '文章搜索','class' => 'input-sm form-control'], ])->label(false) ?> <?= Html::submitButton('Go!', ['class' => 'btn btn-sm btn-primary']) ?> <?php ActiveForm::end(); ?> <?= GridView::widget([ 'dataProvider' => $dataProvider, 'layout'=> '{items}<div class="text-right tooltip-demo">{pager}</div>', 'pager'=>[ //'options'=>['class'=>'hidden']//關(guān)閉自帶分頁 'firstPageLabel'=>"First", 'prevPageLabel'=>'Prev', 'nextPageLabel'=>'Next', 'lastPageLabel'=>'Last', ], //這部分和上面的分頁是一樣的
? ??? ??? ??? ??? ??? ????. . ?? ?? ??? PHP ???? ????? ????.
? ?? ??? ??, ??? ?? ??? ?? ? ?? ??? ??? PHP ??? ????? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











theieldKeyWordinc#simplifiesteratorcreationBeycreationSomateAtAtAtenablesLazyEvaluation.1.ItAllOwSreturningItemSoneatAtimeUsingyieldRetrern, weeneachitem, 2.yieldBreenceCanbeus

DependencyInjection(DI)inC#isadesignpatternthatenhancesmodularity,testability,andmaintainabilitybyallowingclassestoreceivedependenciesexternally.1.DIpromotesloosecouplingbydecouplingobjectcreationfromusage.2.Itsimplifiestestingthroughmockobjectinject

C#?? idisposable? ??? ??? ???? ?? ???? ????? ????? ???? ????. 1. idisposable? dispose () ???? ???? ???? ???? ?? ???? ???? ??? ???? ?? ? ? ???; 2. ?? ???? ??? ??? ??? ?? Dispose ()? ???? ????? ???? ??? ??? ????? ??? ?????. 3.?? ??? ? ??? idisposable? ???? ?? ??? ?? ? ? ??? StreamReader? ?? ??? ?? ???????. 4. ???? ?? ???? ??, ?? ? ??? ???? ???? Dispose (BOOL) ??? ???? ?? ???? ???? ?? ?? ?????.

lambdaexpressionsandlinqsimplifydatamanipulationinc#byenablingconcise, ?? ?? ? ???? ??

NULLABLEREFERENCETYPES (NRTS) INC#8 HELPCATCHNULLREFERNEEXCEPTIONERCECTIONPILETIMEBYMAKINGERENCETYPESNON-NULLABLEBYDEFAULT.NURTSMUSTBEEBEDITHERINTHETHETHE.CSPROJFILEWITHENORATTETTETOPA.CSFILESOUN NULL

C# ???? 4 ?? ???? "??"??? ??????. ??, ???/???? ????? ??? ?? ?? ? ?? ??? ?????. ??? ?? ????? ??? ????, configureawait (false)? ???? ??? ????????. ??, VAR? ?? ??? ???? ???? ??? ??? ??? ??? ? ? ? ??? ?? ??? ???? ?????. ??, ?? ? ?? ??? ?? ???? ??? ???? ?? ???? ???? ?????? IDISPosable ?? ??? ?????????. ??, ?? ??? ?? ?? ?? ???? ?? ??? ???? ???? ??? ??, ? ?? ?? ????? ???? ????? ?? ??? ????????. ??? ??? ??? ?? ??? ?? ??? ?? ?? ? ? ????.

?? ? ???? ??? ??? ????? C# ??? ??????. 1. ??? ?? ??? ??? ?? ???? ?? ??? ??? ????, ?? ?? ????, ??? ?? ? ??? ?? ??? ?????. 2. ???? ??? ??? ?? ??? ????? ???? ?? ????, ?? ? ??? ????? ??? ????? ?????. 3. ? ? GC ??? ??? ??? ????? ?? ??? ????? ??? ??????. 4. SPAN? ???? ???? ??? ???? ???? ????? ??? ???? ??? ? ????. Calling.toArray ()? ?? ? ?? ??? ??? ????????.

??? ??? ?? ?? ?????? ?? ?? ?? ? ?? ?? ??????? 5 ?? ?? ?????. 1. SRP (Single Responsibility Principle)? ???? ??? ?? ?? ? ??? ??? ?? ??? ?? ? ????? ?????. 2. OCP (Opening and Closing Principle)? ISHAPE ?????? ???? ?? ???? ?? ??? ???? ?? ?? ?? ??? ???? ?? ????? ?? ?? ???? ?? ??? ????? ?? ?????. 3. Richter ?? ?? (LSP)? ?? ???? ??? ???? ?? ?? ???? ?? ? ? ??????. 4. ISP (Interface Displence Principle)? ?? ???? ??? ?? ?? ?? ? ?? ??? ?? ??? ?????? ??? ?????. 5. ??? ?? ?? (DIP)?
