While migrating the website. I’m not able to load CSS and JS files in my Codeigniter project.
FOLDER STRUCTURE:
home > username > public_html > application > [ cache , config , controller, core, ... ] home > username > public_html > media > admin > [ attachment, css, datepicl, ...] home > username > public_html > media > front > asset > [css, fonts, img, ...] home > username > public_html > media > uploads > [associatepartner, banner, ..] home > username > public_html > system > [core, database, ..]
config.php
< config < application < public_html
$config['base_url'] = 'http://localhost/domain.com';
header.php
< layout < front < views < application < public_html
<link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/fontawesome-all.min.css"> <link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/reset.css"> <link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/style.css"> <link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/responsive.css">
Help. Thanks! (Do let me know if I need to furnish more details)
EDIT: view-source:http : / / domain.com/ (Please ignore spaces in between http.)
<!-- Bootstrap CSS --> <link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/fontawesome-all.min.css"> <link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/reset.css"> <link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/style.css"> <link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/responsive.css">
EDIT: Added constants.php
constants.php
< config < application < public_html
defined('BASEPATH') OR exit('No direct script access allowed'); if (sSITE_MODE == 'live') { define('URL', 'https://www.theother2thirds.net/'); } else if (sSITE_MODE == 'beta') { define('URL', 'https://www.theother2thirds.net/'); } else { define('URL', 'http://localhost/theother2thirds/'); }
Advertisement
Answer
Your base_url is defined as
$config['base_url'] = 'http://localhost/domain.com';
You will need to load the url helper in your controller or you can autoload it, then you can utilise the function base_url()
.
Then you have a choice of either using
<link rel="stylesheet" type="text/css" href="<?= base_url('asset/css/bootstrap.min.css');?>">
OR you can assign FRONT_MEDIA_URL
defined('FRONT_MEDIA_URL') || define('FRONT_MEDIA_URL', base_url());
BUT you will need to have loaded the url helper prior and you’ve not shown where you have declared that, but that is for you to figure out.
UPDATE due to new information See if you can use this Now I do not know where you are defining sSITE_MODE but this is an option to help with the use of base_url() in your site…
In application/config/config.php you could do something like
defined('sSITE_MODE ') || define('sSITE_MODE', 'live'); if (sSITE_MODE == 'live') { $migration_url = 'https://www.theother2thirds.net/'; } else if (sSITE_MODE == 'beta') { $migration_url = 'https://www.theother2thirds.net/'; } else { $migration_url = 'http://localhost/theother2thirds/'; } $config['base_url'] = $migration_url;
OR just define the correct Constant and use it. You have FRONT_MEDIA_URL in your links and then you are talking about using URL. You need to use the correct one.