-
指向視圖文件: a). $this->renderPartial('index',$data);//$data傳入的參數(shù) b). $this->render('index');//放入$content變量中 $layout = 'common';//顯示公共的common布局文件查看全部
-
yii防止SQL和script注入 <?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>//可以過濾掉<script></script>代碼查看全部
-
模板中數(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; ?>查看全部
-
在一個視圖中顯示另一個視圖: this代表視圖組件,$this->render('另一個視圖的文件名(不用帶擴(kuò)展名)'); 當(dāng)要傳遞參數(shù)給另一個視圖時,用render的第二個參數(shù),$this->render('other', array('key_str','value_str'));查看全部
-
防止 XSS查看全部
-
hasMany, hasOne查看全部
-
關(guān)聯(lián)查詢結(jié)果緩存查看全部
-
customer_id 關(guān)聯(lián)customer和order查看全部
-
關(guān)聯(lián)查詢 例子:顧客表 訂單表查看全部
-
靜態(tài)結(jié)構(gòu)查看全部
-
創(chuàng)建數(shù)據(jù)模型: 類和數(shù)據(jù)庫中表名保持一致,繼承ActiveRecord類(use \yii\app\ActiveRecord),命名空間 namesoace app/models;查看全部
-
在一個視圖中顯示另一個視圖: this代表視圖組件,$this->render('另一個視圖的文件名(不用帶擴(kuò)展名)'); 當(dāng)要傳遞參數(shù)給另一個視圖時,用render的第二個參數(shù),$this->render('other', array('key_str','value_str'));查看全部
-
2015年 6月 25 日聽課筆記 一、請求request 1、訪問自己的控制器里面的方法 r=hello/index hello是控制器名 index是方法名。 2、可以通過get的方式傳遞參數(shù) r=hello/index&id=3 3、在控制器里面,要獲取參數(shù)用 $request = \YII::$app -> request; //獲取參數(shù) echo $result -> get(‘id’); 如果get里面沒有值,可以用這樣的方式給get設(shè)置默認(rèn)值 echo $result -> get(‘id’,20); 如果是post方式,則和get一樣也是 echo $result -> get(‘id’,444); 4.可以通過$request-> isGet和$request -> isPost來判斷是get請求還是post請求。 5、可以通過$request -> userIp 來獲取用戶端的IP地址。 二、響應(yīng)response 1、響應(yīng)http頭的信息,回復(fù)給瀏覽器。 $response = \YII::$app -> response; 設(shè)置404狀態(tài)碼: $response -> statusCode = ‘404’; 是否讓瀏覽器緩存 $response -> add(‘pragma’,’no-cache’); //無緩存 $response -> set(‘pragma’,’,max-age=5’);//緩存設(shè)置成6秒。 $response -> headers -> remove(‘pragram’); 2、設(shè)置瀏覽器跳轉(zhuǎn). $response -> headers -> add(‘location’,’http://www.test.com’); //跳轉(zhuǎn)到test $this -> redirect(‘http://www.test.com’); //和ThinkPHP一樣。 3、文件下載: $response -> headers ->add(‘content-disposition’,’attachment; filename=”a.jpg”’); $responst -> sendFile(‘./robots.txt’); //打開網(wǎng)頁就下載這個文本。查看全部
-
響應(yīng)處理: $res = \YII::response; 更改狀態(tài)碼:$res->statusCode = "404"; 添加header: $res->header->add("pragma", "no-cache"); 修改header: $res->header->set("pragma", "max-age=5"); 刪除header: $res->header->remove("pragma"); 跳轉(zhuǎn): $res->header->add("location", "http://www.baidu.com"); 重定向:$this->redirect("http://www.baidu.com", "302"); 文件下載:$res->header->add("content-disposition", "attachment; filename="a.jpg"); $res->sendFile("./robots.txt");查看全部
-
位于頂層命名空間的全局的類 使用反斜杠 \ 來實(shí)例化查看全部
舉報
0/150
提交
取消