I am using codeigniter framework for a project I have, but I have a small issue I can't solve. I want to separate css styling and js scripts from the views, so I have them in separate folders, /css and /js respectively, both are in the assets folder which is in the root folder of my project. The overall structure is like this:
/project-folder
----/application
----/system
----/assets
--------/css
--------/js
----index.php
Now, I have a controller called MyLibrary that has a method called newentry, which when it gets called loads the newentry view.
<?php
class MyLibrary extends CI_Controller
{
public function newentry()
{
//The upload form
$this->load->view('newentry');
}
}
The newentry view is a simple upload form that uses a style.css and script.js for styling and validation etc... I am using the base_url() method of codeigniter to include the path and file name of the files above.
<html>
<head>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets/css/style.css">
<title><?php echo $title; ?></title>
</head>
<body>
<form class = "dropezone" action = 'upload' method = 'POST' enctype = 'multipart/form-data'>
<input type="file" name="document" />
<input type="submit"/>
</form>
</body>
</html>
This line is where I have a problem: href="assets/css/style.css">
the generated string is the correct path, meaning localhost/project-name/assets/css/styles.css, however, the request gets made to this url:
http://localhost/project-name/MyLibrary/localhost/test-pages/assets/css/style.css
which is of course, not where the files are. Does anyone know why is this happening?
Also, how to fix this? should I add a route by hand? if so, how to make a controller that serves static files?