in a Web site project, it is not necessary to write a common function into a tool class, which is sometimes more convenient for the process. Add in Portal file index.phprequire_once (' protected/function.php ');can be referred to as a common set of functions. function.php as follows:
<? PHP /*** The shortcut to Directory_separator */defined(' ds ') or define(' ds ',directory_separator); defined(' time ') or define(' time ', time()); defined(' MTIME ') or define(' MTIME ', intval(microtime (true))); //Returns the current UNIX timestamp/*** The shortcut to Yii::app () */function app (){return Yii::app ();} /*** The shortcut to Yii::app ()->clientscript */function CS() { //You could also call the client script instance via Yii::app ()->clientscript /Fasterreturn Yii::app ()->getclientscript ();} /*** This was the shortcut to Yii::app ()->user. */function user() { return Yii::app(),getUser(); } /*** The shortcut to Yii::app ()->createurl () */function URL( $route , $params = array (), $ampersand = ' & ' ) { return Yii::app()-createurl( $route , $params ,$ Ampersand ); } /*** The shortcut to Chtml::encode *//* Function h ($text){return Htmlspecialchars ($text, Ent_quotes,yii::app ()->charset);} */ /*** The shortcut to Yii::app ()->request->baseurl* If The parameter is given, it'll be a returned and prefixed with the app BaseUrl. */function baseDir( $url =null) { //static $baseUrl = null; //if ($baseUrl ===null)$baseUrl =yii::app ()->getrequest ()->getbaseurl ();return $url ===null? $BASEURL: $baseUrl. '/'. LTrim ($url, '/');} /*** Returns the named application parameter.* The shortcut to Yii::app ()->params[$name]. */function param( $name ) { return Yii::app(),params[ $name ]; }/*** A useful one that I use with development is the following* which dumps the target with syntax highlighting on by default */function dump( $target ) { return cvardumper::dump( $target , ten, True ) ;} function mk_dir($dir, $mode = 0777) { if (is_dir ( $dir | | @mkdir ( $dir ,< Span class= "PLN" > $mode returntrue if (! Mk_dir(dirname($dir),$mode)) return false; return @mkdir($dir,$mode); } //Customize more Functions ...
Yii uses public functions