2012-04-17 58 views
0

我用這不加載在我viewregistration.php文件BASE_URL在笨

<html> 
<head> 
<link rel="stylesheet" type="text/css" href="<?php echo $base_url; ?><?php echo $css; ?>reg_style.css" /> 
<link rel="stylesheet" type="text/css" href="<?php echo $base_url; ?><?php echo $css; ?>style.css" /> 
</head> 
<body> 
    <?php $this->load->view('include/header');?> 
    <?php $this->load->view('registration_view.php');?> 
    <?php $this->load->view('include/footer');?> 
</body> 
</html> 

而且我打電話在我conltroller作爲

$data['title']= 'Registration'; 
$this->load->view("viewregistration.php", $data); 

而在我的控制,我使用

parent::__construct(); 

     $this->load->helper('url'); 
     $this->load->helper('form'); 

     $this->load->database(); 
     $this->load->model('user_model'); 
     $this->load->model('systemdata'); 

     $this->data['css'] = $this->systemdata->get_css_filespec(); 
     $this->data['scripts'] = $this->systemdata->get_scripts_filespec(); 
     $this->data['base_url'] = $this->systemdata->get_base_url(); 

但是css文件沒有加載。這表明像

A PHP Error was encountered 

Severity: Notice 

Message: Undefined variable: base_url 

A PHP Error was encountered 

Severity: Notice 

Message: Undefined variable: css 

一些錯誤我做錯了嗎? 我已經使用自動加載網址助手。但結果仍然相同。

+0

請顯示如何加載您的視圖文件。 – 2012-04-17 20:38:12

回答

2

你的變量沒有被定義,因爲你實際上並沒有將它們傳遞給你的視圖。 $data$this->data不是一回事。

在這裏,你是正確的$data陣列傳遞到您的視圖:

$data['title']= 'Registration'; 
$this->load->view("viewregistration.php", $data); 

但你如何分配你的變量$this->data,永遠也不會被傳遞到視圖注意這裏:

$this->data['css'] = $this->systemdata->get_css_filespec(); 
$this->data['scripts'] = $this->systemdata->get_scripts_filespec(); 
$this->data['base_url'] = $this->systemdata->get_base_url(); 

您需要將變量分配給$data或將$this->data傳遞給您的視圖。

1

我不認爲這一行是必要的。

$this->data['base_url'] = $this->systemdata->get_base_url(); 

你可以做什麼,而不是,這是。

<link rel="stylesheet" type="text/css" href="<?php echo base_url($css.'reg_style.css'); ?>" /> 

base_url()是一個CI函數,它爲您提供基礎url。

信息來源:http://codeigniter.com/user_guide/helpers/url_helper.html