PHP code example of svyatov / yii-shortcut

1. Go to this page and download the library: Download svyatov/yii-shortcut library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

svyatov / yii-shortcut example snippets


// Standart code
Yii::app()->controller->createUrl('user/login');

// Y code
Y::url('user/login');

// Standart code
Yii::app()->cache->get('user_settings');
Yii::app()->cache->set('user_settings', $userSettings);

// Y code
Y::getCache('user_settings');
Y::setCache('user_settings', $userSettings);

// Y code
Y::getCookie('user_settings');
Y::setCookie('user_settings', $userSettings);

// Standart code
Yii::app()->request->csrfToken;

// Y code
Y::csrf();

// Standart code
echo '<pre>';
CVarDumper::dump($testVariable, 10, true);
Yii::app()->end();

// Y code
Y::dump($testVariable);

// Standart code
echo $result;
Yii::app()->end();
// or
echo json_encode($result);
Yii::app()->end();

// Y code
Y::end($result);
// or
Y::endJson($result);

// Standart code
$this->redirect($this->createUrl('user/settings')); // the shortest example
Yii::app()->request->redirect(Yii::app()->controller->createUrl('user/settings')); // if we inside some widget

// Y code
Y::redirect('user/settings'); // you can use wherever you want, controller/widget, it doesn't matter

// Standart code
if (Yii::app()->user->isGuest) {} // is user a guest?
// or
if (!Yii::app()->user->isGuest) {} // is user authenticated?

// Y code
if (Y::isGuest()) {} // is user a guest?
// or
if (Y::isAuthenticated()) {} // is user authenticated?
// the code speaks for himself, it's more expressive and readable
phtml
// Standart code
<script>
$.post('/user/login', {<?=Yii::app()->request->csrfTokenName;