版权声明:本文为博主原创文章,未经博主允许不得转载。
YII2.0自带的有2个项目目录一个是前台的frontend和后台的backend,访问的时候必须访问至http://localhost:8080/phpblog/backend/web/index.php?r=admin/index,这样好像很麻烦,而且难记,于是我们把访问的地址配置成http://localhost:8080/phpblog/admin.php这种的就好记很多了.
首先在backend下面找到web目录:
把里面的index.php复制到根目录并改名字为admin.php:
修改admin.php里面的内容为:
- <?php
- defined(‘YII_DEBUG‘) or define(‘YII_DEBUG‘, true);
- defined(‘YII_ENV‘) or define(‘YII_ENV‘, ‘dev‘);
- require(__DIR__ . ‘/vendor/autoload.php‘);
- require(__DIR__ . ‘/vendor/yiisoft/yii2/Yii.php‘);
- require(__DIR__ . ‘/common/config/bootstrap.php‘);
- require(__DIR__ . ‘/backend/config/bootstrap.php‘);
- #require(__DIR__ . ‘/common/config/autoload.php‘);
- $config = yii\helpers\ArrayHelper::merge(
- require(__DIR__ . ‘/common/config/main.php‘),
- require(__DIR__ . ‘/common/config/main-local.php‘),
- require(__DIR__ . ‘/backend/config/main.php‘),
- require(__DIR__ . ‘/backend/config/main-local.php‘)
- );
- $application = new yii\web\Application($config);
- $application->language=‘zh-CN‘;
- $application->defaultRoute=‘admin‘;
- $application->run();
找到backend目录下面的assets目录下面的AppAsset.php,修改内容
- class AppAsset extends AssetBundle
- {
- public $basePath = ‘@webroot‘;
- public $baseUrl = ‘@web‘;
- //全局的js和css,主要是修改这里的路径,原来的@web不能使用了,要写backend的全路径了,按照下面的写就可以了
- public $css = [
- ‘backend/web/scripts/css/default.css‘,
- ‘backend/web/scripts/js/jquery-easyui-1.4.3/themes/icon.css‘,
- ‘backend/web/scripts/js/jquery-easyui-1.4.3/themes/easyui_icons.css‘,
- ‘backend/web/scripts/js/jquery-easyui-1.4.3/themes/default/easyui.css‘
- ];
- public $js = [
- ‘backend/web/scripts/js/jquery-easyui-1.4.3/jquery.min.js‘,
- ‘backend/web/scripts/js/jquery-easyui-1.4.3/jquery.easyui.min.js‘
- ];
- public $depends = [
- ];
- //定义按需加载JS方法,注意加载顺序在最后
- public static function addScript($view, $jsfile) {
- $view->registerJsFile($jsfile, [‘depends‘=>[‘backend\assets\AppAsset‘]]);
- }
- //定义按需加载css方法,注意加载顺序在最后
- public static function addCss($view, $cssfile) {
- $view->registerCssFile($cssfile, [‘depends‘=>[‘backend\assets\AppAsset‘]]);
- }
- }
- <?php
- $params = array_merge(
- require(__DIR__ . ‘/../../common/config/params.php‘),
- require(__DIR__ . ‘/../../common/config/params-local.php‘),
- require(__DIR__ . ‘/params.php‘),
- require(__DIR__ . ‘/params-local.php‘)
- );
- return [
- ‘id‘ => ‘app-backend‘,
- ‘basePath‘ => dirname(__DIR__),
- ‘bootstrap‘ => [‘log‘],
- ‘controllerNamespace‘ => ‘backend\controllers‘,
- ‘components‘ => [
- //添加了这个配置
- ‘assetManager‘ => [
- ‘basePath‘ => ‘@webroot/backend/web/assets‘,
- ‘baseUrl‘ => ‘@web/backend/web/assets‘
- ],
- ‘user‘ => [
- ‘identityClass‘ => ‘common\models\User‘,
- ‘enableAutoLogin‘ => true,
- ],
- ‘log‘ => [
- ‘traceLevel‘ => YII_DEBUG ? 3 : 0,
- ‘targets‘ => [
- [
- ‘class‘ => ‘yii\log\FileTarget‘,
- ‘levels‘ => [‘error‘, ‘warning‘],
- ],
- ],
- ],
- ‘errorHandler‘ => [
- ‘errorAction‘ => ‘site/error‘,
- ],
- ],
- ‘params‘ => $params,
运行效果:
希望可以帮助到大家。
- 顶
- 2
- 踩
- 0
- 1楼 软件高手_20162016-12-10 09:24发表 [回复]
- 正在学习Yii2.0,通过这篇文件发现了,Yii2.0和EasyUI结合的用法。谢谢