简体   繁体   English

如何在Codeigniter中将我的在线站点更改为本地站点?

[英]How to change my online site to local in codeigniter?

I am downloading my site online to my local machine. 我正在将网站在线下载到本地计算机上。 The database is done set up. 数据库设置完成。

My question is how can change all the navigation in the application within local? 我的问题是如何更改本地应用程序中的所有导航?

this is my config file 这是我的配置文件

$config['base_url'] = 'https://www.yiyalo.com/';

this is an example of sign up 这是注册的例子

<a href='<?php echo base_url();  ?>signup/' target="_self" >

so that it will go to https://www.yiyalo.com/signup when the link is press. 这样在按下链接时它将转到https://www.yiyalo.com/signup

Now, how can I perform that in localhost so that I can modify the code in the localhost? 现在,如何在localhost中执行该操作,以便可以在localhost中修改代码?

My file is stored in a folder called ' yiyalo '. 我的文件存储在名为yiyalo的文件夹中。

If you want a version that will work on both your local machine and your server, I'd recommend populating $config['base_url'] depending on your $_SERVER['HTTP_HOST'] value, as such : 如果您想要一个既可以在本地计算机上运行又可以在服务器上运行的版本,我建议根据$_SERVER['HTTP_HOST']值填充$config['base_url'] ,例如:

if ($_SERVER['HTTP_HOST'] == 'localhost') {
    $config['base_url'] = 'http://localhost/';
} else {
    $config['base_url'] = 'https://www.yiyalo.com/';
}

A nicer approach is to set it up via enviromental variable: 更好的方法是通过环境变量进行设置:

$config['base_url']=getenv('BASE_URL');

So in you run via Apache you can put: 因此,在通过Apache运行时,您可以输入:

SetEnv BASE_URL "https://www.yiyalo.com/"

In case of cgi with nginx you can pass it as fastcgi_param eg: 如果使用nginx的cgi,则可以将其作为fastcgi_param传递,例如:

location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    #extra fastcgi params there
    fastcgi_param BASE_URL "https://www.yiyalo.com/"
}

Alternatively in case of a docker use ENV directive into your Dockerfile. 另外,如果是Docker,请在您的Dockerfile中使用ENV指令。

The sole reassonn I am saying to use enviromental variable is that in case of a local php webserver that php provides you can just export them (assuming that you develop over GNU/Linux or similar): 我唯一要使用的环境变量是在php提供的本地php网络服务器的情况下,您可以exportexport (假设您是通过GNU / Linux或类似软件开发的):

export BASE_URL=http://localhost

So each developer just needs to export its own environment in order to run the app. 因此,每个开发人员仅需要导出自己的环境即可运行该应用程序。

try the code below.Go to application/config/config.php and change this 尝试下面的代码。转到application / config / config.php并更改它

switch ($_SERVER['HTTP_HOST']) {
    case 'yiyalo.com':
      $config['base_url'] = 'https://www.yiyalo.com/';
    break;
    default:
      $config['base_url'] ='http://localhost/yiyalo/';
       break;
      }

Change your base_url to: 将您的base_url更改为:

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

Make sure you have a proper .htaccess in the root of the project (localhost/yiyalo in this case). 确保在项目的根目录中有适当的.htaccess (在本例中为localhost / yiyalo)。

Remember that you can let $config['base_url'] empty as well. 请记住,您也可以使$ config ['base_url']为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM