I am new to Codeigniter and I am trying to use Codeigniter 4. What do I have to do in order for me to load my CSS and JS file? I have been spending for the past 7 hours trying to figure out what's wrong but still can't find any solution.
This is my folder structure:
-app
-public
--css
---styles.css
--js
---mainjs.js
--img
-system
-writable
The file is there and I even tried to put the exact path instead of using base_url but I keep getting either file not found error or internal server error message. The tutorial or guide I see on the net, all I saw was pointing the path to the file location and it works for them. There are limited answers posted here too which is based on Codeigniter 4.
.env file
app.baseURL = 'http://localhost/ci/'
app/Controllers/Pages.php
<?php namespace App\Controllers;
class Pages extends BaseController
{
public function index()
{
return view('index');
}
public function view($page)
{
if ( ! is_file(APPPATH.'/Views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
}
$data['title'] = ucfirst($page); // Capitalize the first letter
echo view('templates/header', $data);
echo view('pages/'.$page, $data);
echo view('templates/footer', $data);
}
//--------------------------------------------------------------------
}
app/Views/templates/header.php
<!DOCTYPE html>
<html lang="en-US" class="no-js">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="<?php echo base_url('public/css/style.css'); ?>" type="text/css" media="all" />
</head>
Hope there's someone here who can help me out on this issue. Thanks in advance.