I am working on web page in CodeIgniter in my localhost but this webpage is also in live server.
base_url() for all links.
<link rel="stylesheet" href="<?= base_url() ?>assets/style.css"> <script src="<?= base_url() ?>assets/jquery-ui.min.js"></script> ... <a href="<?= base_url() ?>show/edit/other">
When I click on link in localhost it gives mi live server address, so I can't do anything in localhost.
Can somebody help me please?
You can create two folders inside
application/config one for production(live server) and one for development(localhost)
- development => application/config/development
- production => application/config/production
Then copy any file in the main
application/config folder and paste it into both
$config['base_url'] = 'http://localhost';
$config['base_url'] = 'http://example.com';
Based on your ENV constant in
index.php it will load settings from either production or development folders. So if ENV == 'development' the settings in
application/config/development will get used.
If you want a relative path to your assets, add this to the
HEAD of your html
<base href="<?php echo base_url();?>" />
Then you can just ref your assets like so
<link rel="stylesheet" href="assets/styles.css" />