冰辉 发表于 2018-10-11 15:33:19

请教个入门的问题,怎么设置开发环境呢?

本帖最后由 冰辉 于 2018-10-11 23:34 编辑

不好意思,很多东西不会。

下载的代码默认是产品模式,请问怎么配置为开发环境呢?
看英文文档说要设置: CI_ENVIRONMENT = development
文档说在env文件改,但是codeigniter目录下的env文件没有这一项;
application目录下,的.env文件也没有这一项。

这个东西在哪里设置,我还没弄清楚,因此厚着脸皮要请教了。

冰辉 发表于 2018-10-11 15:38:32

文档说
环境常量CodeIgniter 默认使用 $_SERVER['CI_ENVIRONMENT'] 的值作为 ENVIRONMENT 常量,否则默认就是 'production'。这样能够根据不同服务器安装环境定制不同的环境依赖。
codeigniter/env 和 application/.env 都加了
CI_ENVIRONMENT = development

没有效果,因为是IIS,不是apache和nginx,文档没有说明iis下的处理方法。

Hex 发表于 2018-10-11 23:59:41

建议还是装一个 xampp 这样集成开发环境,否则开源社区基本上没有用 IIS 的,所以你会碰到很多问题,建议使用大家都在用的工具。

冰辉 发表于 2018-10-12 18:43:40

因为真实环境会在IIS下;没办法,只能用笨办法了:

找到 application\Config\Boot 里面
1、把production.php 备份;
2、development.php创建一个备份,改名production.php;就可以看到错误信息了。

Hex 发表于 2018-10-12 18:49:56

冰辉 发表于 2018-10-12 18:43
因为真实环境会在IIS下;没办法,只能用笨办法了:

找到 application\Config\Boot 里面


竟然服务器是 IIS。。。。。。。。。。。。。。

冰辉 发表于 2018-10-15 21:49:25

这几天没弄,今晚弄了下;
一开始想像.NET哪样,在web.config文件设置;发现不行,web服务无法解释配置文件;

后来想到IIS+php一般是用fastcgi模式,看了下IIS配置,Fastcgi里面有环境变量的设置,加上去就可以了。



冰辉 发表于 2018-10-15 21:52:07

本帖最后由 冰辉 于 2018-10-15 21:53 编辑

development,开发模式下,会在视图插入一段html,引用js脚本和style,搞得网页样式都变形了,体验不大好。

<script type="text/javascript"id="debugbar_loader" data-time="1539611434" src="http://127.0.0.1/v3/index.php?debugbar"></script><script type="text/javascript"id="debugbar_dynamic_script"></script><style type="text/css"id="debugbar_dynamic_style"></style>


冰辉 发表于 2018-10-15 21:57:07

开发模式下,插入的js是这样的:


document.addEventListener('DOMContentLoaded', loadDoc, false);

function loadDoc(time) {
      if (isNaN(time)) {
                time = document.getElementById("debugbar_loader").getAttribute("data-time");
                localStorage.setItem('debugbar-time', time);
      }

      localStorage.setItem('debugbar-time-new', time);

      var url = "http://127.0.0.1/v3/index.php";

      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
                if (this.readyState === 4 && this.status === 200) {
                        var toolbar = document.getElementById("toolbarContainer");
                        if (!toolbar) {
                              toolbar = document.createElement('div');
                              toolbar.setAttribute('id', 'toolbarContainer');
                              document.body.appendChild(toolbar);
                        }

                        // copy for easier manipulation
                        let responseText = this.responseText;

                        // get csp blocked parts
                        // the style block is the first and starts at 0
                        {
                              let PosBeg = responseText.indexOf( '>', responseText.indexOf( '<style' ) ) + 1;
                              let PosEnd = responseText.indexOf( '</style>', PosBeg );
                              document.getElementById( 'debugbar_dynamic_style' ).innerHTML = responseText.substr( PosBeg, PosEnd )
                              responseText = responseText.substr( PosEnd + 8 );
                        }
                        // the script block starts right after style blocks ended
                        {
                              let PosBeg = responseText.indexOf( '>', responseText.indexOf( '<script' ) ) + 1;
                              let PosEnd = responseText.indexOf( '</script>' );
                              document.getElementById( 'debugbar_dynamic_script' ).innerHTML = responseText.substr( PosBeg, PosEnd - PosBeg );
                              responseText = responseText.substr( PosEnd + 9 );
                        }
                        // check for last style block
                        {
                              let PosBeg = responseText.indexOf( '>', responseText.lastIndexOf( '<style' ) ) + 1;
                              let PosEnd = responseText.indexOf( '</style>', PosBeg );
                              document.getElementById( 'debugbar_dynamic_style' ).innerHTML += responseText.substr( PosBeg, PosEnd - PosBeg );
                              responseText = responseText.substr( 0, PosBeg );
                        }

                        toolbar.innerHTML = responseText;
                        if (typeof ciDebugBar === 'object') {
                              ciDebugBar.init();
                        }
                } else if (this.readyState === 4 && this.status === 404) {
                        console.log('CodeIgniter DebugBar: File "WRITEPATH/debugbar/debugbar_' + time + '" not found.');
                }
      };

      xhttp.open("GET", url + "?debugbar_time=" + time, true);
      xhttp.send();
}

// Track all AJAX requests
var oldXHR = window.XMLHttpRequest;

function newXHR() {
      var realXHR = new oldXHR();
      realXHR.addEventListener("readystatechange", function() {
                // Only success responses and URLs that do not contains "debugbar_time" are tracked
                if (realXHR.readyState === 4 && realXHR.status.toString() === '2' && realXHR.responseURL.indexOf('debugbar_time') === -1) {
                        var debugbarTime = realXHR.getResponseHeader('Debugbar-Time');
                        if (debugbarTime) {
                              var h2 = document.querySelector('#ci-history > h2');
                              h2.innerHTML = 'History <small>You have new debug data.</small> <button>Update</button>';
                              var badge = document.querySelector('a > span > .badge');
                              badge.className += ' active';
                        }
                }
      }, false);
      return realXHR;
}

window.XMLHttpRequest = newXHR;
页: [1]
查看完整版本: 请教个入门的问题,怎么设置开发环境呢?