1.定义params 打开: /config/params.php return [ "domain" => [ 'www' => 'http://forum', //根目录 'm' => 'http://forum/m', //m方法类 'web' => 'http://forum/web' //web方法类 ] ]; 2.在根目录下创建common文件夹,并创建Services文件夹里面的UrlServices.php文件 namespace app\controllers; use yii\helpers\Url; class UrlService { public static function buildWebUrl($path,$params = []){ $domain_config = \Yii::$app->params['domain']; $path = Url::toRoute(array_merge([$path],$params)); return $domain_config['web'].$path; } public static function buildMUrl($path,$params = []){ $domain_config = \Yii::$app->params['domain']; $path =Url::toRoute(array_merge([$path],$params)); return $domain_config['m'].$path; } public static function buildWwwUrl($path,$params = []){ $domain_config = \Yii::$app->params['domain']; $path =Url::toRoute(array_merge([$path],$params)); return $domain_config['www'].$path; } public static function buildNullUrl(){ return "javascript:void(0)"; } }
林外听秋风