0

I am using this in my viewregistration.php file

<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. 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.

1
  • Please show how you're loading your view file. Commented Apr 17, 2012 at 20:38

2 Answers 2

2

Your variables aren't defined because you're not actually passing them to your view. $data and $this->data are not the same thing.

Here, you are correctly passing the $data array to your view:

$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['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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Sources: http://codeigniter.com/user_guide/helpers/url_helper.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.