-
關(guān)聯(lián)查詢查看全部
-
common.php查看全部
-
視圖數(shù)據(jù)過(guò)濾查看全部
-
<?php use yii\helpers\Html; ?> <h1><?=Html::encode($view_hello_str);?></h1>查看全部
-
視圖傳遞數(shù)據(jù)查看全部
-
$cookie = \YII::$app->response->cookie; $cookie_data=array('name'=>'user','value'=>'zhangsi'); $cookes->add(new Cookie($cookie_data)); $cookies->remove('id'); $cookies = \YII::$app-.request->cookies; echo $cookies->getValue('users',20);查看全部
-
關(guān)聯(lián)查詢結(jié)果緩存 unset($customer->orders) //關(guān)聯(lián)查詢的多次查詢 $customers = Customer::find()->with('orders')->all() foreach($customers as $customer){ $orders = $customer->orders }查看全部
-
關(guān)聯(lián)查詢: hasMany:一對(duì)多,hasOne:一對(duì)一 $customer->orders; $customer當(dāng)沒(méi)有orders屬性時(shí),$customer自動(dòng)調(diào)用_get()方法,拼接調(diào)用getOrders()方法,并自動(dòng)在后面加上all()方法或者one()方法,至于何時(shí)自動(dòng)拼接all或者one,取決于關(guān)聯(lián)查詢是用的hasMany還是hasOne,如果是hasMany則拼接all,否則反之。 //關(guān)聯(lián)查詢 //根據(jù)顧客查詢她/他的訂單的信息 // $customer = Customer::find()->where(['name'=>'zhangsan'])->one(); // $order = $customer->hasMany('app\models\Order',['customer_id'=>'id'])->asArray()->all(); // $orders = $customer->getOrders(); // $orders = $customer->orders; // print_r($orders); //根據(jù)訂單查詢顧客的信息 $order = Order::find()->where(['id'=>1])->one(); $customer = $order->customer; //以屬性的方式獲取數(shù)據(jù) print_r($customer); 注:若使用以屬性的方式獲取數(shù)據(jù),則在模型里面要定義一個(gè)方法,該方法要以get+屬性的命名方式。查看全部
-
添加數(shù)據(jù): helloController.php文件: $test = new Test; $test->id = 3; $test->title = 'title3'; $test->validate();//驗(yàn)證器,驗(yàn)證字段是否合法 if($test->hasErrors()){ echo 'data is error';//字段不合法 die; } $test->save(); 如果想要驗(yàn)證,在模型test.php文件中有對(duì)應(yīng)的方法rules進(jìn)行驗(yàn)證 test.php: public function rules(){ return [ ['id','integer'],['title','string','length'=>[0,5]]]; }查看全部
-
表單刪除: delete();先從表中查找出來(lái),查出來(lái)的是一個(gè)對(duì)象,然后再調(diào)用對(duì)象里的delete方法進(jìn)行刪除 $res = Test::find()->where(['id'=>1])->all(); $res[0]->delete(); deleteAll(); 直接使用deleteAll進(jìn)行刪除 Test::deleteAll('id>:id',array(':id'=>0));刪除id大于0的數(shù)據(jù)查看全部
-
數(shù)據(jù)模型: 1,和表名一致的文件; 2,引入命名空間:namespace app\models; 3, 使用命名空間:use yii\db\ActiveRecord; 4, 創(chuàng)建與表名一致的類并繼承ActiveRecord; class tablename extends ActiveRecord{}查看全部
-
模板中數(shù)據(jù)塊使用方式 <?php $this->beginBlock('block1');?> <h1>index111</h1> <?php $this->endBlock();?> 在布局模板中就這樣顯示 //判斷顯示數(shù)據(jù)塊有木有,然后在顯示 <?php if(isset($this->blocks['block1'])):?> <?=$this->blocks['block1'];?> <?php else: ?> <h1>hello Common </h1> <?php endif; ?> <?=$this->blocks['block1'];?> <?=$content; ?>查看全部
-
在一個(gè)視圖(index.php)中顯示另一個(gè)試圖(about.php): 在視圖index.php文件中使用$this->render('about')顯示about視圖; 當(dāng)需要傳入?yún)?shù)時(shí),用render的第二個(gè)參數(shù):$this->render('about',array('key'=>'value'))查看全部
-
render兩種作用,第一是放到$content中,第二是顯示layout布局查看全部
-
<?php use yii\helpers\Html; use yii\helpers\HtmlPurifier; ?> <P><?=Html::encode($view_hello_str) ?> </P>//可以原樣顯示<script></script>代碼 <P><?=HtmlPurifier::process($view_hello_str) ?> </P>//可以過(guò)濾掉<script></script>代碼查看全部
舉報(bào)
0/150
提交
取消