I am trying to learn Codeigniter. I have built a simple MVC following the tutorials on the CI site. This is my controller…
<?php
class Pages extends CI_Controller {
public function view($page = 'home'){
if(!file_exists(APPPATH.'/views/pages/'.$page.'.php')){
show_404();
}
$data['title'] = ucfirst($page);
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
Here is the header template…
<html>
<head>
<title><?php echo $title ?> - WurkWithUs</title>
<link rel="stylesheet" href="http://localhost/ci/CodeIgniter_2.1.2/css/bootstrap.css" type="text/css" media="screen"/>
<link rel="stylesheet" href="http://localhost/ci/CodeIgniter_2.1.2/css/custom.css" type="text/css" media="screen"/>
</head>
<body>
<h1>Wurk With Us</h1>
The style sheets work when I use an absolute path like the one above. However if I try to use something like…
<link rel="stylesheet" href="<?= base_url()?>css/bootstrap.css" type="text/css" media="screen"/>
I get a blank page. When I “view page source” my style line looks like…
<link rel="stylesheet" href="
I have tried to follow the suggestions here and I get the same results i.e. document stops being parsed at the “href=” line.
What am I doing wrong? Is there a better way to load my stylesheets?
I’ve had this issue many, many times. I’d bet money you’re not loading in the URL helper. It does not autoload, so either load it in your controller or autoload it.
If you choose to lead it in your controller, call
before you load the view.
The reason you see the
hrefblank in the source is because there was a PHP error at that point (it could not find the methodbase_url())