我试图像这样回应base_url():
editor_header.php
<link href="<?php echo base_url(); ?>/css/bootstrap.css" rel="stylesheet" media="screen">
editor_header.php的控制器如下所示:
<?php
class Pages extends CI_Controller {
public function view($page = 'home')
{
if ( ! file_exists('application/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('head&foot/editor_header', $data);
}
}
?>
我在autoload.php中启用了url_helper,就像这样
$autoload['helper'] = array('url');
但我仍然得到错误:
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /Applications/XAMPP/xamppfiles/htdocs/editor/application/controllers/pages.php on line 5
pages.php是上面的控制器。
请问有什么人建议为什么editor_header.php不能使用base_url?提前谢谢。
答案 0 :(得分:1)
更改您的控制器代码,看它是否有效
class Pages extends CI_Controller {
public function view($page = 'home')
{
$path = APPPATH . 'views/pages' . $page . '.php';
if ( ! file_exists($path))
{
show_404();
}
$data['title'] = ucfirst($page);
$this->load->view('head&foot/editor_header', $data);
}
}