2017 © Pedro Peláez
 

library yii-shortcut

Shortcuts for Yii framework

image

svyatov/yii-shortcut

Shortcuts for Yii framework

  • Monday, August 25, 2014
  • by svyatov
  • Repository
  • 9 Watchers
  • 41 Stars
  • 197 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Y

Shortcuts for Yii framework v1.1, (*1)

Install

php composer.phar require svyatov/yii-shortcut '~2.0', (*2)

via download

Get the latest release and put Y.php file in your application protected/components folder., (*3)

Usage

Creating URL by route in a widget

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

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

Get/set some cache value

// 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);

The same with cookies

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

Getting the value of CSRF token

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

// Y code
Y::csrf();

Inserting CSRF name and token in some jQuery request

// Standart code






// Y code





Quick variable dump with code highlighting

// Standart code
echo '

<

pre>';
CVarDumper::dump($testVariable, 10, true);
Yii::app()->end();

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

Short action ending without template rendering (e.g. for AJAX requests)

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

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

Redirects

// 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

Detecting current user status (is he a guest or is he authenticated)

// 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

As you can see, the amount of code becomes at least 2 times smaller. So you need to type at least 2 times less and you can read it and understand it at least 2 times faster., (*4)

Changelog

  • v2.0.0 / 26.08.2014, (*5)

    new Added new methods: module() and component()., (*6)

    chg Removed protected method _getComponent()., (*7)

    chg Removed method getRequest()., (*8)

    chg Protected method _getValueByComplexKeyFromArray() renamed to getValueByComplexKeyFromArray() and changed to public., (*9)

    chg Methods getGet(), getPost() and getFiles() renamed to GET(), POST() and FILES() respectively., (*10)

    chg Method isAuthed() renamed to isAuthenticated()., (*11)

    chg Method redir() renamed to redirect()., (*12)

    chg Method flashRedir() renamed to flashAndRedirect()., (*13)

    chg Methods redirAuthed() and redirGuest() renamed to redirectIfAuthenticated() and redirectIfGuest() respectively., (*14)

    chg Method hasAccess() renamed to checkAccess()., (*15)

    chg Setters, getters and deleters for cache, cookie and session renamed to comply common pattern, e.g.: cacheSet() -> setCache()., (*16)

  • v1.3.2 / 05.05.2014, (*17)

    fix Composer autoloading fixed., (*18)

    chg Scope of _getComponent() and _getValueByComplexKeyFromArray() methods changed to protected., (*19)

    chg README.md enhanced and style updated., (*20)

    chg phpDoc comments light reformat., (*21)

  • v1.3.1 / 28.09.2013, (*22)

    fix Fixed urls to repo. No code changed., (*23)

  • v1.3.0 / 12.07.2013, (*24)

    new Everything is translated to English., (*25)

    new Added LICENSE file., (*26)

    chg Updated composer.json file., (*27)

    chg Added second argument $options to cookieDelete() method., (*28)

    chg Added $secure and $httpOnly arguments to cookieSet() method. Besides, $value argument could be an instance of CHttpCookie class now., (*29)

    chg CSRF token name in method csrfJsParam() now quoted., (*30)

    chg Default $message argument value in flash() method changed to 'false' so now there is a way to remove flash message by passing 'null' as $message argument., (*31)

    chg Added $params and $allowCaching arguments to hasAccess() method. It doesn't change previous behaviour but extending method abilities., (*32)

    chg Code refactoring., (*33)

  • v1.2.1 / 25.01.2012, (*34)

    new Added method getFile()., (*35)

  • v1.2.0 / 20.10.2011, (*36)

    new Added methods: format, script, session, sessionGet, sessionSet, sessionDelete., (*37)

    new Added internal caching of application components., (*38)

    chg cookieDelete() method now returns the object of removed cookie (like the original method)., (*39)

  • v1.1.5 / 29.09.2011, (*40)

    new Added method dbCmd()., (*41)

    fix Fixed errors in @since phpDoc tags., (*42)

  • v1.1.4 / 27.09.2011, (*43)

    fix Fixed bug in cookieSet() method, which prevents setting cookie if there was no $expire argument., (*44)

    chg Cookie methods now use native methods of the CCookieCollection class., (*45)

  • v1.1.3 / 19.07.2011, (*46)

    new Added methods: getGet, getPost, getRequest, getPdo, hasFlash., (*47)

    chg cache(), cacheDelete(), cacheGet(), cacheSet() methods now have $cacheId argument, which gives the ability to select different cache backends., (*48)

    chg Added $options argument to endJson() method, which gives the ability to pass options to native json_encode() function., (*49)

    chg More "magic" removed. Code refactoring., (*50)

  • v1.1.0 / 29.05.2011, (*51)

    new Added methods: isAjaxRequest, isPutRequest, isDeleteRequest, isPostRequest, isSecureConnection., (*52)

    new Added changelog to README. README.markdown renamed to README.md, (*53)

    chg Removed almost every "magic" inside methods., (*54)

    chg Added $absolute argument to baseUrl() method, which gives the ability to get absolute URL instead of relative one., (*55)

    chg Added $default argument to cookieGet() method, which gives the ability to return value of $default variable if cookie with specified name doesn't exist., (*56)

    chg Added $default argument to param() method, which gives the ability to return value of $default variable if parameter with specified name doesn't exist. Also, method code refactored., (*57)

    chg Fixed and enhanced phpDoc comments., (*58)

  • v1.0.4 / 05.01.2011, (*59)

    chg Code refactoring. Class uploaded to GitHub., (*60)

  • v1.0.3 / 16.12.2010, (*61)

    fix Fixed bug in param() method., (*62)

  • v1.0.2 / 16.12.2010, (*63)

    new Added method hasAccess()., (*64)

    new Enhanced method param(). Now key could contain dot delimited string to access nested variables. For example: 'site.title' returns value at param['site']['title']. Thanks for idea to sergebezborodov., (*65)

    chg Code refactoring., (*66)

The Versions

25/08 2014

dev-master

9999999-dev https://github.com/svyatov/Yii-shortcut

Shortcuts for Yii framework

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.2

 

helper yii util shortcut

25/08 2014

v2.0.0

2.0.0.0 https://github.com/svyatov/Yii-shortcut

Shortcuts for Yii framework

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.2

 

helper yii util shortcut

05/05 2014

v1.3.2

1.3.2.0 https://github.com/svyatov/Yii-shortcut

Shortcuts for Yii framework

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.2

 

helper yii util shortcut

29/09 2013

v1.3.1

1.3.1.0 https://github.com/svyatov/Yii-shortcut

Shortcuts for Yii framework

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.2

 

helper yii util shortcut

26/07 2013

v1.3.0

1.3.0.0 https://github.com/Svyatov/Yii-shortcut

Shortcuts for Yii framework

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.2

 

helper yii util shortcut

21/05 2013

v1.2.1

1.2.1.0 https://github.com/Svyatov/Yii-shortcut

Shortcuts for Yii framework

  Sources   Download

BSD

The Requires

  • php >=5.3.0

 

yii shortcut