-
響應(yīng)主鍵和請(qǐng)求主鍵類似,通過(guò)$res = \YII::$app->response;獲取,然后設(shè)置狀態(tài)碼$res->statusCode = '404'查看全部
-
通過(guò)post方式接收參數(shù) $request->post(名稱,默認(rèn)值) $request->isGet $request->isPost查看全部
-
使用請(qǐng)求組件的get方式獲取 \YII::app->request() $request->get(id);查看全部
-
如果參數(shù)當(dāng)中r=hello/index&id=3傳遞到控制器中,控制器要用到請(qǐng)求組件接收 $request = YII::app->request//用于接收瀏覽器傳遞過(guò)來(lái)的id,并放到變量$request中查看全部
-
namespace app\Controllers use yii\web\controller class HelloController extends Controller { function actionIndex(){ echo "hello word" } } 訪問(wèn)的時(shí)候的參數(shù)就是r=hello/index其中hell代表控制器,index代表控制器的方法查看全部
-
session.save_path查看全部
-
表單刪除: 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{}查看全部
-
在一個(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'))查看全部
-
$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>使用默認(rèn)數(shù)據(jù)塊</h1> <?php endif;?>即可替換數(shù)據(jù)塊。查看全部
-
public $layout = 'common'; public function actionIndex(){ return $this->render('index'); //把視圖文件里的內(nèi)容保存到$content變量中 }查看全部
-
<h1><?=\yii\helpers\Html::encode($view_hello_str);?></h1> 進(jìn)行轉(zhuǎn)義 <h1><?=\yii\helpers\HtmlPurifier::process($view_hello_str);?></h1> 徹底過(guò)濾查看全部
-
//視圖 $hello_str = 'hello'; //字符串 $test_arr = array(1,2); //1.創(chuàng)建數(shù)組 $data = array(); //2.把需要傳遞給視圖的數(shù)據(jù)放到數(shù)組當(dāng)中 $data['view_hello_str'] = $hello_str; $data['view_test_arr'] = $test_arr; //把數(shù)組里的數(shù)據(jù)傳遞給index視圖 return $this->renderPartial('index',$data);查看全部
-
使用父類Controller中的方法renderPartial()來(lái)調(diào)用視圖,然后返回顯示給瀏覽器。 return $this->renderPartial('視圖標(biāo)志');查看全部
-
//cookie處理 // $cookies = Yii::$app->response->cookies; // $cookie_data = array('name'=>'user','value'=>'wang'); // $cookies->add(new yii\web\Cookie($cookie_data)); // $cookies->remove('user'); // $cookies = Yii::$app->request->cookies; // echo $cookies->getValue('users',20); //獲取cookie數(shù)據(jù)查看全部
舉報(bào)
0/150
提交
取消