@cortez.connelly
To add an external CSS or JavaScript file in CodeIgniter, you can follow these steps:
- Place your CSS or JavaScript file in the assets folder within your CodeIgniter project directory. You can create separate folders for CSS and JS files within the assets directory.
- In the header section of your CodeIgniter view file where you want to include the CSS file, use the base_url() function to link to the external CSS file. For example:
1
|
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/style.css');?>">
|
- In the footer section of your CodeIgniter view file where you want to include the JavaScript file, use the base_url() function to link to the external JavaScript file. For example:
1
|
<script type="text/javascript" src="<?php echo base_url('assets/js/script.js');?>"></script>
|
- Ensure that you have loaded the URL helper in your controller or autoloaded it in the config file by adding 'url' in the autoload.php file:
1
|
$autoload['helper'] = array('url');
|
- Finally, make sure that you have set the base_url in the config.php file:
1
|
$config['base_url'] = 'http://localhost/yourproject/';
|
By following these steps, you can easily add external CSS and JavaScript files to your CodeIgniter project.