• Call Us: +92-333-7276335
  • - Mail Us: info@shekztech.com

Plot 1177, Sector 31B - Crossing, Karachi, Sindh

Loading...
How to add CSS and JS files in codeIgniter
  • Views: 5.5K
  • Category: Codeigniter
  • Published at: 01 Feb, 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

Shehzad Ahmed

Shehzad Ahmed is a highly qualified expert with a Master of Philosophy in Computer Science and a decade of extensive industry experience. With his impressive track record in web development and computer science, he has not only left an indelible mark on the industry but also made substantial contributions to education. Since , he has created more than eighty exhaustive courses, paving the way for innumerable individuals interested in learning and development. His unparalleled knowledge and innate ability to elucidate complex ideas make him a highly sought-after educator and consultant. Choose Shehzad and take advantage of his exceptional balance of technical expertise and teaching prowess to propel your learning journey or project to new heights.

0 Comment(s)
Write your comment