-
靜態(tài)方法findBySql where(['>,''id','0']) id>1 對(duì)象占用的內(nèi)存高 ->asAraay() 轉(zhuǎn)化為數(shù)組降低內(nèi)存,查看全部
-
$cookies->getVlaue('user')查看全部
-
數(shù)據(jù)模型: 1,和表名一致的文件; 2,引入命名空間:namespace app\models; 3, 使用命名空間:use yii\db\ActiveRecord; 4, 創(chuàng)建與表名一致的類(lèi)并繼承ActiveRecord; class tablename extends ActiveRecord{}查看全部
-
$layout = common ; //布局文件 $this 視圖組件 如果想替換公共文件中的某段(數(shù)據(jù)塊),可以在視圖文件中使用: <?php $this->beginBlock('block1'); ?> <h1>....</h1> <?php $this->endBlock();?> 公共文件中調(diào)用 <?=$this->blocks['block1'];?> 判斷顯示數(shù)據(jù)塊有木有,然后在顯示 <?php if(isset($this->blocks['block1'])):?> <?=$this->blocks['block1'];?> <?php else: ?> <h1>hello Common </h1> <?php endif; ?>查看全部
-
在一個(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'))查看全部
-
防止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>//可以過(guò)濾掉<script></script>代碼查看全部
-
布局文件 /views/laysout/查看全部
-
session.save_path session 保存的路徑,在php.ini中設(shè)置 $session->set(); $session->get()取出session數(shù)據(jù) $session->remove()刪除session數(shù)據(jù) /可以通過(guò)數(shù)組方式進(jìn)行操作session $session[] = '' unset($sission[])//刪除 //兩張方式,一種是對(duì)象方式處理,另一種是數(shù)組方式查看全部
-
相應(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ù)據(jù) $result = Test::find()->where(['id'=>4])->one(); $result->title="title4"; $result->save();查看全部
-
<?php namespace app\models; use yii\db\ActiveRecord; use yii\validators; /** * */ class Test extends ActiveRecord { public function rules(){ return [ ['id','integer'], ['title','string','length'=>[0,5]] ]; } } //HelloController //添加數(shù)據(jù) $test = new Test; $test->id="dss"; $test->title="title3"; $test->validate(); if($test->hasErrors()){ echo "data is error "; die; } $test->save();查看全部
-
//刪除數(shù)據(jù) //$results = Test::find()->where(['id'=>1])->all(); //$results[0]->delete(); Test::deleteAll('id>:id',array(':id'=>0));查看全部
-
//查詢(xún)數(shù)據(jù) // $sql="SELECT * FROM test"; // $results = Test::findBySql($sql)->all(); //id=1 // $results = Test::find()->where(["id"=>1])->all(); // print_r($results); //id>0 /*$results = Test::find()->where(['>','id',0])->all(); print_r($results);*/ //id>=1 and id<=2 //$results = Test::find()->where(['between','id',1,2])->all(); //echo count($results); //title like '%title%' //$results=Test::find()->where(['like','title','title'])->all(); //print_r($results); //將查詢(xún)結(jié)果轉(zhuǎn)換成數(shù)組 // $results=Test::find()->where(['like','title','title'])->asArray()->all(); //批量查詢(xún) foreach ($Test::find()->batch(2) as $value) { # code... } print_r($results);查看全部
-
dsf查看全部
-
$sql="select * from test where id=:id";//占位符 $result = Test::findysql($sql,array('id'=>'1'))->all();查看全部
舉報(bào)
0/150
提交
取消