Home >Backend Development >PHP Tutorial >Summary of common path methods in Yii_PHP tutorial
A summary of how to use some common path methods in the Yii framework.
Add CSS files or JavaScript files in the controller:
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/my.css'); Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/css/my.js'); <?php echo $this->module->assetsUrl; ?>/css/main.css
Call the js of framework/web/js/source in the YII framework. The file called by the registerCoreScript key can be viewed in the framework/web/js/packages.php list:
Yii::app()->clientScript->registerCoreScript('jquery');
Get the ID of the current controller in the view:
Yii::app()->getController()->id;
Get the ID method of the current action in the view:
Yii::app()->getController()->getAction()->id;
yii gets ip address
Yii::app()->request->userHostAddress;
yii determines whether the submission method is a post request
Yii::app()->request->isPostRequest
yii determines whether it is an ajax request
Yii::app()->request->isAjaxRequest
Get the current domain name:
Yii::app()->request->hostInfo
Get the physical path of the protected directory
YII::app()->basePath;
Get the url of the previous page to return
Yii::app()->request->urlReferrer;
Get the current url
Yii::app()->request->url;
Get current home url
Yii::app()->homeUrl
Get the current return url
Yii::app()->user->returnUrl
Project path
dirname(Yii::app()->BasePath)
If you have a directory with some commonly used classes or files, you can define a path alias at the top of main.php, and the alias can be translated into its corresponding path.
Yii::getPathOfAlias('webroot')
If there are multiple configurations, you can add a configuration to the array in main.php.