i'm developing a web application with php codeigniter. in views folder, i created header.php that contains css and js and etc files and footer.php for footer of pages.
in default controller, when i use $this->load->view('header')
, it's Ok. but when i use this command in other pages, css files can not load. in inspect element i've got errors that says in css file path, codeigniter added index.php/ctrl_name
to this address.
this is path of my css file:
http://localhost:9000/CRM/index.php/home/assets/css/materialize.min.css
Best Answer
Load url helper in application/config/autoload.php
$autoload['helper'] = array('url');
Set base_url config in application/config/config.php
$config['base_url'] = 'http://localhost/MyProject';
In header.php, include js and css like this:
<link href="<?=base_url();?>assets/css/materialize.min.css" rel="stylesheet">
Good luck!