-
//session處理 $session = Yii::$app->session; $session->open(); //開啟session //判斷session是否開啟 // if($session->isActive){ // echo 'session is active'; // } //對象方式 // $session->set('user','汪'); //設(shè)置session值 // echo $session->get('user'); //取session值 // $session->remove('user'); //刪除session值 //數(shù)組方式 // $session['user'] = 'wang'; // echo $session['user']; // unset($session['user']);查看全部
-
namespace是用來區(qū)分不同位置的相同類名,use關(guān)鍵字用來定義重復(fù)的位置,as用來進行修改相同類名,直接\是用來引用頂層空間的文件查看全部
-
nice!查看全部
-
關(guān)聯(lián)查詢性能問題: 1、查詢結(jié)果緩存,可以使用unset($customer->orders)刪除查詢緩存 2、關(guān)聯(lián)查詢的多次查詢:with('屬性') eg:Customer::find()->with('orders')->all(); //select * from order where customer_id in(...)查看全部
-
關(guān)聯(lián)查詢: hasMany:一對多,hasOne:一對一 $customer->orders; $customer當(dāng)沒有orders屬性是,$customer自動調(diào)用_get()方法,拼接調(diào)用getOrders()方法,并自動在后面加上all()方法或者one()方法,至于何時自動拼接all或者one,取決于關(guān)聯(lián)查詢是用的hasMany還是hasOne,如果是hasMany則拼接all,否則反之。查看全部
-
新的框架查看全部
-
非常好查看全部
-
好好好查看全部
-
修改數(shù)據(jù)查看全部
-
添加數(shù)據(jù): helloController.php文件: $test = new Test; $test->id = 3; $test->title = 'title3'; $test->validate();//驗證器,驗證字段是否合法 if($test->hasErrors()){ echo 'data is error';//字段不合法 die; } $test->save(); 如果想要驗證,在模型test.php文件中有對應(yīng)的方法rules進行驗證 test.php: public function rules(){ return [ ['id','integer'],['title','string','length'=>[0,5]]]; }查看全部
-
表單刪除: delete();先從表中查找出來,查出來的是一個對象,然后再調(diào)用對象里的delete方法進行刪除 $res = Test::find()->where(['id'=>1])->all(); $res[0]->delete(); deleteAll(); 直接使用deleteAll進行刪除 Test::deleteAll('id>:id',array(':id'=>0));刪除id大于0的數(shù)據(jù)查看全部
-
查詢數(shù)據(jù): 防止SQL注入:使用SQL占位符 :id $sql = "select * from table where id=:id"; Test::findBySql($sql,array(':id'=>1))->all(); $result = Test::find()->where(['between','id',1,2])->all(); $result查出來的最外層是數(shù)組,數(shù)組里是一條一條的對象。 asArray()是將查詢結(jié)果轉(zhuǎn)化為數(shù)據(jù) Test::find()->where([])->asArray()->all()查看全部
-
創(chuàng)建數(shù)據(jù)模型: 命名空間 namespace app\models; use yii\db\ActiveRecord; 類繼承ActiveRecord查看全部
-
$layout = common ; //布局文件 $this 視圖組件 如果想替換公共文件中的某段(數(shù)據(jù)塊),可以在視圖文件中使用: <?php $this->beginBlock('block1'); ?> <h1>....</h1> <?php $this->endBlock();?> 公共文件中調(diào)用 <?php if(isset($this->blocks['block1']));?> <?=$this->blocks['block1'];?> <?php else;?> <h1>使用默認數(shù)據(jù)塊</h1> <?php endif;?>即可替換數(shù)據(jù)塊。查看全部
-
在一個視圖(index.php)中顯示另一個試圖(about.php): 在視圖index.php文件中使用$this->render('about')顯示about視圖; 當(dāng)需要傳入?yún)?shù)時,用render的第二個參數(shù):$this->render('about',array('key'=>'value'))查看全部
舉報
0/150
提交
取消