Translate

Thursday, 1 October 2020

How to link Css and Js Files in Codeigniter 4

1) Download Any Template Html/bootstrap.

2)Past all css/js files in codeigniter project/public folder 


3) Add all html files in View folder rename that file .html to .php file and load view in controller like below shown.

   <?php namespace App\Controllers;
   use CodeIgniter\Controller;
   class User extends BaseController
   {
     public function index()
     {
       return view('home');
     }

     public function about()
     {
       return view('about');
     }

   }
 

4) in header section of view give modify css link 
<link href="main.css" rel="stylesheet"></link> 
TO
<link href="<?php echo site_url('public/main.css');?>" rel="stylesheet"></link>
Same above apply to js file link also Example.
<script src="scripts/main.js" type="text/javascript"></script>
TO
<script src="<?php echo site_url('public/assets/scripts/main.js');?>" type="text/javascript"></script>


5) Add Your template will Installed properly.

I have created Youtube video with practical you watch that and learn more. Link is Given below.