![How to add CSS and JS files in codeIgniter](https://shekztech.com/storage/images/blogs/1693572831.webp)
- Views: 6.2K
- Category: Codeigniter
- Published at: 31 Jan, 2017
- Updated at: 01 Sep, 2023
How to add CSS and JS files in codeIgniter
How to add CSS and JS files in CodeIgniter
If you are a web developer and working on PHP, you always add your CSS and JS files to your project, but it's hard to add CSS and js files if you are working on a framework. Today I will show you how to add CSS and js files using CodeIgniter.
How to attach/add CSS and JS files in CodeIgniter..? It is simple to attach/add CSS files using CodeIgniter; if you want to add CSS and js files to the application folder, you should create a folder named assets in your application folder.
Now create CSS and js folders and create your CSS file named style.css and put it into the CSS folder; now, create your js file named script.js and keep it in the js folder. Open your view to add CSS and JS file links to use APPPATH.
What is APPPATH..?
APPPATH is the path to your application folder.
APPPATH."assets/css/style.css"
APPPATH."assets/js/script.js"
<!DOCTYPE html>
<html>
<head>
<title>Add CSS And JS files in Codeigniter</title>
<link rel="stylesheet" type="text/css" href="<?php echo APPATH.'assets/css/style.css'?>">
<script type="text/javascript" src="<?php echo APPATH.'assets/js/script.js'?>"></script>
</head>
<body>
If you want to create an assets folder in your CodeIgniter root directory, create an assets folder in root, open your assets folder, create a CSS file named style.css, put it into the CSS folder, and create your js file called script.js and keep it into js folder.
<!DOCTYPE html>
<html>
<head>
<title>Add CSS And JS files in Codeigniter</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/style.css')?>">
<script type="text/javascript" src="<?php echo base_url('assets/js/script.js')?>"></script>
</head>
<body>
Now open your view to attach css and js links use baser_url() Note before using baser_url() function in codeigniter you must load URL Helper, you can load URL Helper in your controller $this->load->helper('url'); OR you can autoload URL Helper find autoload file in your application/config/autoload.php and find $autoload['helper'] = array('url');
https://www.youtube.com/watch?v=NNHW7w0HSmg
0 Comment(s)