Yii 2 0常用方法記錄

2021-07-11 08:00:50 字數 2091 閱讀 3602

// $headers is an object of yii\web\headercollection 

// returns the accept header value

$accept = $headers->get('accept');

if ($headers->has('user-agent'))

if ($session->isactive) ...
$session->open();
$session->close();
$session

->destroy();

從 "request"元件中獲取cookie集合(yii\web\cookiecollection)

- 獲取名為 "language" cookie 的值,如果不存在,返回預設值"en"

$language = $cookies->getvalue('language', 'en');

- 另一種方式獲取名為 "language" cookie 的值

if (($cookie = $cookies->get('language')) !== null)

- 可將 $cookies當作陣列使用

if (isset($cookies['language']))

// 判斷是否存在名為"language" 的 cookie

if ($cookies->has('language')) ...

if (isset($cookies['language'])) ...

<?php

$form = activeform::begin(['action' => ['test/getpost'],

'method'=>'post',

]); ?>

<?

echo

$form->field($model, 'username')->textinput(['maxlength' => 20])?>

<?

echo

$form->field($model, 'password')->passwordinput(['maxlength' => 20])?>

<?

echo

$form->field($model, '***')->radiolist(['1'=>'男','0'=>'女'])?>

<?

echo

$form->field($model, 'edu')->dropdownlist(['1'=>'大學','2'=>'高中','3'=>'初中'],

['prompt'=>'請選擇','style'=>'width:120px'])?>

<?

echo

$form->field($model, 'file')->fileinput()?>

<?

echo

$form->field($model, 'hobby')->checkboxlist(['0'=>'籃球','1'=>'足球','2'=>'羽毛球','3'=>'桌球'])?>

<?

echo

$form->field($model, 'info')->textarea(['rows'=>3])?>

<?

echo

$form->field($model, 'userid')->hiddeninput(['value'=>3])?>

<? echohtml::submitbutton('提交', ['class'=>'btn btn-primary','name' =>'submit-button'])?>

<? echohtml::resetbutton('重置', ['class'=>'btn btn-primary','name' =>'submit-button'])?>

<?phpactiveform::end(); ?>

$config[『components』][『assetmanager』][『forcecopy』] = true;

YII2 0 常用查詢語句

1.首先理解以下三個的返回型別 find 返回值是乙個activequery 物件 hasone 與 hasmany 返回值是 yii db activequery instance activedataprovider 返回的值是 yii db activequery instance2.下面詳細...

yii2 0 加密解密處理方法

yii提供了方便的幫助函式來讓你用乙個安全秘鈅來加密解密資料。資料通過加密函式進行傳輸,這樣只有擁有安全秘鑰的人才能解密。比如,我們需要儲存一些資訊到我們的資料庫中,但是,我們需要保證只有擁有安全秘鑰的人才能看到它 即使應用的資料庫洩露 data 是你要加密的內容,secretkey 是你自己設定的...

Yii2 0如何建立公共方法

yii2 advanced版本 common 目錄為公共資源目錄,我們可以把定義的方法放在這個目錄下,在此目錄下我們隨意建立乙個檔案比如 helps 目錄,因為考慮到公共方法可能會有功能上的劃分類,所以建立乙個統一目錄來進行管理。自定義全域性公共方法 class tools 直接在控制器中呼叫 pu...