yii2常用路径获取

时间:2024-05-23 17:03:38
public function actionGetUrlList()
{
echo "当前域名地址:".Yii::$app->request->hostInfo."<br>";
echo "当前目录物理路径:".Yii::$app->basePath."<br>";
echo "当前项目路径:".dirname(Yii::$app->BasePath)."<br>";
echo "当前Url: ".Yii::$app->request->url."<br>";
echo "当前Home Url: ".Yii::$app->homeUrl."<br>";
echo "当前return Url: ".Yii::$app->user->returnUrl."<br>";
echo "获取当前模块ID方法:".Yii::$app->controller->module->id."<br>";
echo "获取当前控制器的ID方法:".Yii::$app->controller->id."<br>";
echo "获取当前action的ID方法:".Yii::$app->controller->action->id."<br>";
echo "ip地址: ".Yii::$app->request->userIP."<br>";
echo "上一个绝对Url":".Yii::$app->request->referrer."<br/>";
echo "返回绝对路径:".Yii::$app->urlManager->createAbsoluteUrl('a/b')."<br/>"
echo "是否启用路由美化".Yii::$app->urlManager->enablePrettyUrl."<br/>";
}