zoukankan      html  css  js  c++  java
  • Yii 2.0 GII 访问404错误

    网上大部分都是普通的开启和配置资料 
    按照网上资料配置 访问localhost/index/php?r=gii 总是提示404错误 

    解决方法如下: 
    Yii基础版中的 web.php 代码如下

    if (YII_ENV_DEV) {
        // configuration adjustments for 'dev' environment
        $config['bootstrap'][] = 'debug';
        $config['modules']['debug'] = [
            'class' => 'yiidebugModule',
            // uncomment the following to add your IP if you are not connecting from localhost.
            //'allowedIPs' => ['127.0.0.1', '::1'],
        ];
    
        $config['bootstrap'][] = 'gii';
        $config['modules']['gii'] = [
            'class' => 'yiigiiModule',
            // uncomment the following to add your IP if you are not connecting from localhost.
            'allowedIPs' => ['127.0.0.1', '::1'],
        ];
    }

    注意这里的变量是YII_ENV_DEV 而在入口文件index.php中配置的是

    defined('YII_DEBUG') or define('YII_DEBUG', true);
    defined('YII_ENV') or define('YII_ENV','dev');
    //需要根绝web.php中的变量YII_ENV_DEV增加对应的开启设置
    defined('YII_ENV_DEV ') or define('YII_ENV_DEV ', true);
    
    require(__DIR__ . '/../vendor/autoload.php');
    require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
    
    $config = require(__DIR__ . '/../config/web.php');
    
    (new yiiwebApplication($config))->run();

    2.路由配置 
    enablePrettyUrl 设置为false

    //路由配置
            'urlManager' => [
               'enablePrettyUrl' => false,//路由的路径化 去掉 ?r=
               'showScriptName' => false,//隐藏入口Index.php文件
                //'suffix' => '.html',//假后缀(fake suffix) .html
                'rules' => [
                    '<controller:w+>/<name:w+>/<action:w+>'=>'<controller>/<action>',
                    'company/<id:d+>.html'=>'company/list',
                ],
            ],

    3.GII是基于本地访问使用的 所有使用localhost或127.0.0.1来访问。

  • 相关阅读:
    帧锁定同步算法
    为 Raft 引入 leader lease 机制解决集群脑裂时的 stale read 问题
    etcd:从应用场景到实现原理的全方位解读
    给定一个二叉搜索树(BST),找到树中第 K 小的节点
    UDP如何实现可靠传输
    理解TCP/IP三次握手与四次挥手的正确姿势
    Redis持久化
    Redis提供的持久化机制(RDB和AOF)
    redis渐进式 rehash
    redis rehash
  • 原文地址:https://www.cnblogs.com/liangzia/p/10882783.html
Copyright © 2011-2022 走看看