简体   繁体   English

base_url未加载到codeigniter中

[英]base_url not loading in codeigniter

I am using this in my viewregistration.php file 我在我的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>

And I am calling it in my conltroller as 我在控制器中称它为

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

And in my controller I am using 在我的控制器中

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();

But the css file is not loading. 但是css文件未加载。 It show some error like 它显示出一些错误,例如

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: base_url

and

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: css

What I am doing wrong? 我做错了什么? I have used autoload url helper. 我已经使用了自动加载网址帮助程序。 But the result remains same. 但是结果仍然相同。

Your variables aren't defined because you're not actually passing them to your view. 您没有定义变量,因为您实际上没有将它们传递给视图。 $data and $this->data are not the same thing. $data$this->data不是同一件事。

Here, you are correctly passing the $data array to your view: 在这里,您可以正确地将$data数组传递给视图:

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

But notice here how you're assigning your variables to $this->data , which never gets passed to the view: 但是请注意,您是如何将变量分配给$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();

You either need to assign your variables to $data or pass $this->data to your view. 您需要将变量分配给$data或将$this->data传递给视图。

I dont think this line is necessary. 我认为这行不是必要的。

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

What you can do instead, is this. 您可以做的是这个。

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

base_url() is a CI function that gives you, the base url. base_url()是一个CI函数,为您提供基本URL。

Sources: http://codeigniter.com/user_guide/helpers/url_helper.html 资料来源: http : //codeigniter.com/user_guide/helpers/url_helper.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM