svyatov / yii-shortcut
Shortcuts for Yii framework
Installs: 210
Dependents: 0
Suggesters: 0
Security: 0
Stars: 39
Watchers: 7
Forks: 4
Open Issues: 0
pkg:composer/svyatov/yii-shortcut
Requires
- php: >=5.3.2
This package is not auto-updated.
Last update: 2025-11-03 21:10:22 UTC
README
Shortcuts for Yii framework v1.1
Install
via Composer (recommended)
php composer.phar require svyatov/yii-shortcut '~2.0'
via download
Get the latest release and put Y.php file in your application protected/components folder.
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 <script> $.post('/user/login', {<?=Yii::app()->request->csrfTokenName;?>: '<?=Yii::app()->request->csrfToken;?>', ...} ...); </script> // Y code <script> $.post('/user/login', {<?=Y::csrfJsParam();?>, ...} ...); </script>
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.
Changelog
-
v2.0.0 / 26.08.2014
newAdded new methods: module() and component().chgRemoved protected method _getComponent().chgRemoved method getRequest().chgProtected method _getValueByComplexKeyFromArray() renamed to getValueByComplexKeyFromArray() and changed to public.chgMethods getGet(), getPost() and getFiles() renamed to GET(), POST() and FILES() respectively.chgMethod isAuthed() renamed to isAuthenticated().chgMethod redir() renamed to redirect().chgMethod flashRedir() renamed to flashAndRedirect().chgMethods redirAuthed() and redirGuest() renamed to redirectIfAuthenticated() and redirectIfGuest() respectively.chgMethod hasAccess() renamed to checkAccess().chgSetters, getters and deleters for cache, cookie and session renamed to comply common pattern, e.g.: cacheSet() -> setCache(). -
v1.3.2 / 05.05.2014
fixComposer autoloading fixed.chgScope of _getComponent() and _getValueByComplexKeyFromArray() methods changed to protected.chgREADME.md enhanced and style updated.chgphpDoc comments light reformat. -
v1.3.1 / 28.09.2013
fixFixed urls to repo. No code changed. -
v1.3.0 / 12.07.2013
newEverything is translated to English.newAdded LICENSE file.chgUpdated composer.json file.chgAdded second argument $options to cookieDelete() method.chgAdded $secure and $httpOnly arguments to cookieSet() method. Besides, $value argument could be an instance of CHttpCookie class now.chgCSRF token name in method csrfJsParam() now quoted.chgDefault $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.chgAdded $params and $allowCaching arguments to hasAccess() method. It doesn't change previous behaviour but extending method abilities.chgCode refactoring. -
v1.2.1 / 25.01.2012
newAdded method getFile(). -
v1.2.0 / 20.10.2011
newAdded methods: format, script, session, sessionGet, sessionSet, sessionDelete.newAdded internal caching of application components.chgcookieDelete() method now returns the object of removed cookie (like the original method). -
v1.1.5 / 29.09.2011
newAdded method dbCmd().fixFixed errors in @since phpDoc tags. -
v1.1.4 / 27.09.2011
fixFixed bug in cookieSet() method, which prevents setting cookie if there was no $expire argument.chgCookie methods now use native methods of the CCookieCollection class. -
v1.1.3 / 19.07.2011
newAdded methods: getGet, getPost, getRequest, getPdo, hasFlash.chgcache(), cacheDelete(), cacheGet(), cacheSet() methods now have $cacheId argument, which gives the ability to select different cache backends.chgAdded $options argument to endJson() method, which gives the ability to pass options to native json_encode() function.chgMore "magic" removed. Code refactoring. -
v1.1.0 / 29.05.2011
newAdded methods: isAjaxRequest, isPutRequest, isDeleteRequest, isPostRequest, isSecureConnection.newAdded changelog to README. README.markdown renamed to README.mdchgRemoved almost every "magic" inside methods.chgAdded $absolute argument to baseUrl() method, which gives the ability to get absolute URL instead of relative one.chgAdded $default argument to cookieGet() method, which gives the ability to return value of $default variable if cookie with specified name doesn't exist.chgAdded $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.chgFixed and enhanced phpDoc comments. -
v1.0.4 / 05.01.2011
chgCode refactoring. Class uploaded to GitHub. -
v1.0.3 / 16.12.2010
fixFixed bug in param() method. -
v1.0.2 / 16.12.2010
newAdded method hasAccess().newEnhanced 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.chgCode refactoring.