Advertisement
Guest User

Untitled

a guest
Dec 8th, 2011
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.68 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Dump a variable to output buffer
  5.  * @param mixed $var a variable to dump
  6.  * @return string HTML dump of parameter
  7.  */
  8. function dump($var) {
  9.     CVarDumper::dump($var, 10, true);
  10.     return $var;
  11. }
  12.  
  13. /**
  14.  * Shortcut to Yii::trace()
  15.  * @param mixed $x the message to trace
  16.  * @return mixed the argument passed in
  17.  * @param bool $export to var_export the value of $x
  18.  */
  19. function trace($x, $export = false) {
  20.     Yii::trace($export ? var_export($x, true) : $x);
  21.     return $x;
  22. }
  23.  
  24. /**
  25.  * DIRECTORY_SEPARATOR
  26.  */
  27. defined('DS') or define('DS',DIRECTORY_SEPARATOR);
  28.  
  29. /**
  30.  * @return CApplication Yii::app()
  31.  */
  32. function app() {
  33.     return Yii::app();
  34. }
  35.  
  36. /**
  37.  * @return CClientScript Yii::app()->clientScript
  38.  */
  39. function cs() {
  40.     return Yii::app()->getClientScript();
  41. }
  42.  
  43. /**
  44.  * @return CAuthManager Yii::app()->authManager
  45.  */
  46. function am() {
  47.     return Yii::app()->getAuthManager();
  48. }
  49.  
  50. /**
  51.  * @return CWebUser Yii::app()->user
  52.  */
  53. function user() {
  54.     return Yii::app()->getUser();
  55. }
  56.  
  57. /**
  58.  * Sets or gets user state. getter if $val is null. setter otherwise
  59.  * @param string $key state store key
  60.  * @param null $val key for the stored data
  61.  * @return mixed the stored data
  62.  */
  63. function state($key, $val = null) {
  64.     if ($val === null)
  65.         return Yii::app()->getUser()->getState($key);
  66.     else
  67.         return Yii::app()->getUser()->getState($key, $val);
  68. }
  69.  
  70. /**
  71.  * Shortcut to Yii::app()->createUrl()
  72.  * @param string $route controller/action-type route
  73.  * @param array $params
  74.  * @param string $ampersand
  75.  * @return string
  76.  */
  77. function url($route, $params=array(), $ampersand='&') {
  78.     return Yii::app()->createUrl($route,$params,$ampersand);
  79. }
  80.  
  81. /**
  82.  * Shortcut to CHtml::encode
  83.  * @param string $text raw text to encode
  84.  * @return string
  85.  */
  86. function h($text) {
  87.     return htmlspecialchars($text, ENT_QUOTES, Yii::app()->charset);
  88. }
  89.  
  90. /**
  91.  * Shortcut to CHtml::link()
  92.  * @param string $text raw link text
  93.  * @param string $url link URL or route
  94.  * @param array $htmlOptions
  95.  * @return string HTML link tag
  96.  */
  97. function l($text, $url = '#', $htmlOptions = array()) {
  98.     return CHtml::link($text, $url, $htmlOptions);
  99. }
  100.  
  101. /**
  102.  * Shortcut to Yii::t() with default category = 'stay'
  103.  * @param string $message soure language text
  104.  * @param string $category translation library
  105.  * @param array $params string params
  106.  * @param string $source source language
  107.  * @param string $language target language
  108.  * @return string translated text
  109.  */
  110. function t($message, $category = 'dca', $params = array(), $source = null, $language = null) {
  111.     return Yii::t($category, $message, $params, $source, $language);
  112. }
  113.  
  114. /**
  115.  * Quotes a string value for use in a query.
  116.  * @param string $s string to be quoted
  117.  * @return string the properly quoted string
  118.  * @see http://www.php.net/manual/en/function.PDO-quote.php
  119.  */
  120. function q($s) {
  121.     return Yii::app()->db->quoteValue($s);
  122. }
  123.  
  124. /**
  125.  * Shortcut to Yii::app()->request->baseUrl
  126.  * If the parameter is given, it will be returned and prefixed with the app baseUrl.
  127.  * @param string $url a relative url to prefix with baseUrl
  128.  * @return string
  129.  */
  130. function bu($url=null) {
  131.     static $baseUrl;
  132.     if ($baseUrl===null)
  133.         $baseUrl=Yii::app()->getRequest()->getBaseUrl();
  134.     return $url===null ? $baseUrl : $baseUrl.'/'.ltrim($url,'/');
  135. }
  136.  
  137. /**
  138.  * Shortcut to Yii::app()->params[$name].
  139.  * @param $name
  140.  * @return mixed the named application parameter
  141.  */
  142. function param($name) {
  143.     return Yii::app()->params[$name];
  144. }
  145.  
  146. /**
  147.  * @param string $str subject of test for integerness
  148.  * @return bool true if argument is an integer string
  149.  */
  150. function intStr($str) {
  151.     return !!preg_match('/^\d+$/', $str);
  152. }
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement