Bilişim dünyasına kaliteli, özgün ve Türkçe içerikler kazandırmayı hedefleyen bir platform..

friends friends friends

Yii2 Framework Cookies

Gelin hep beraber Cookie'lere bir göz atalım: Nasıl oluşturulurlar, nasıl okunurlar, nasıl silinirler ya da kendimize göre nasıl bazı ayarlamalar yapabiliriz.

Set Cookies

Cookie oluşturmak için aşağıdaki kodları kullanabilirsiniz:

<?php
$cookies = Yii::$app->response->cookies;
// add a new cookie to the response to be sent
$cookies->add(new \yii\web\Cookie([
    'name' => 'username',
    'value' => 'yiiuser',
    'expire' => time() + 86400 * 365,
]));
?>

Get Cookies

Cookie çağırmak için aşağıdaki kodları kullanabilirsiniz:

<?php
$cookies = Yii::$app->request->cookies;
// get the cookie value 
$username = $cookies->getValue('username');
//return default value if the cookie is not available
$username = $cookies->getValue('username', 'default');
// Check the availability of the cookie
if ($cookies->has('username')){
    echo $cookies->getValue('username');
}
?>

Remove Cookies

Cookie silmek için aşağıdaki kodları kullanabilirsiniz:

<?php
$cookies = Yii::$app->response->cookies;
$cookies->remove('username');
unset($cookies['username']);
?>
Yii2 Framework Cookies Set Cookies Get Cookies Remove Cookies using cookies enable cookie disable cookie setting a cookie Cookies Handling Cookie management
0 Beğeni
Yii2 Framework
Önceki Yazı

Yii2 Framework Current Controller, Module ve Action

15 Ekim 2020 tarihinde yayınlandı.
Sonraki Yazı

PHP Composer

15 Ekim 2020 tarihinde yayınlandı.
arrow