Yii uses public functions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.