doubi6303 2015-03-07 07:57
浏览 55
已采纳

在发布之前在codeigniter中更改baseurl

I want to publish my codeigniter website.

Now it is located in '../htdocs/site/' folder. and the base_url is:

$config['base_url'] = 'http://localhost/site'; 

Should I copy the 'site' folder to real server and change the base_url like this:

$config['base_url'] = 'http://example.com/site';

or there is another way so that I can hide '/site' in the URL ?

This is my first project and your help is highly appreciated.

Update:

Root/
      -Application1
      -System1
      -Site1/
                    -index.php
                    -css
                    -js
                   -images
      -Application2
      -System2
      -Site2/
                    -index.php
                    -css
                    -js
                   -images
  • 写回答

3条回答 默认 最新

  • dsfdfdfd6576578 2015-03-07 10:09
    关注

    You don't need to duplicate your application for each environement. Codeigniter can handle multiple configurations. You just need to set one folder per environment.

    Let's suppose the following organization :

    Root/
          -Application
          -System
          -Assets           
             -css
             -js
             -images
    
          -index.php
    

    We will have 3 environments: Dev/Testing/Production.

    We know that our application will have a different base_url and database conf depending on the environment. It means that we will need to modify config.php and database.php each time we will move our app from an env to an other.

    CodeIgniter provides us an easy way to do that :

    http://www.codeigniter.com/user_guide/general/environments.html

    http://www.codeigniter.com/user_guide/libraries/config.html#environments

    We just need to set 3 folders inside application/config

    -application
          -config
             - development
             - testing
             - production
    

    Inside those new folders, just place the config files which will be different on each environement. In our case, config.php and database.php

    -application
          -config
             - development 
                  -config.php
                  -database.php
             - testing
                  -config.php
                  -database.php 
             - production
                  -config.php
                  -database.php
             - autoload.php
             - ...
    

    Finally, in the root index.php just have to modify the following line to tell CI in which environement it is :

    define('ENVIRONMENT', 'development'); //for dev env
    define('ENVIRONMENT', 'testing'); //for testing env
    define('ENVIRONMENT', 'production'); //for prod env
    

    development/testing/production are defaults environements in CI but you can create your own just by creating your folders in application/config and modifying the switch in the root index.php :

    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL);
        break;
        case 'server':
            error_reporting(E_ALL);
        break;
        case 'testing':
        case 'production':
            error_reporting(0);
        break;
       /*CUSTOM ENV :*/
        case 'custom_env':
            error_reporting(E_ALL);
        break;
        default:
            exit('The application environment is not set correctly.');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog