我在viewregistration.php
文件
<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>
我在我的控制器中称它为
$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
我做错了什么? 我使用过autoload url helper。但结果仍然相同。
答案 0 :(得分: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 :(得分: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