[英]Can't use base_url() in Codeigniter
我試圖像這樣回顯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? 提前致謝。
像這樣更改您的控制器代碼以查看其是否有效
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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.