Welcome Guest, Not a member yet? Register   Sign In
Message: Undefined variable: css
#1

[eluser]jzmwebdevelopement[/eluser]
Hey,

I am unsure why I am getting the Error: Message: Undefined variable: css in my view. I have checked the user guide and googled I am a bit stumped:

Controller:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Header extends CI_Controller {


public function index()
{
  $data['css'] = "css";
  
  $this->load->view('admin/assets/header', $data);
}
}

View:

Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;!-- Le HTML5 shim, for IE6-8 support of HTML elements --&gt;
    &lt;!--[if lt IE 9]>
      [removed][removed]
    <![endif]--&gt;
  &lt;/head&gt;
&lt;body&gt;

<p>&lt;?php echo $css; ?&gt;</p>
#2

[eluser]InsiteFX[/eluser]
Code:
public function index()
{
  $data = array();

  $data['css'] = "css";
  
  $this->load->view('admin/assets/header', $data);
}

If that does not fix then It could be a reserved html word, try changing the name and see if it goes away.
#3

[eluser]vincej[/eluser]
You appear not to be applying a valid value to $data['css'] in your controller.
#4

[eluser]jzmwebdevelopement[/eluser]
[quote author="vincej" date="1328595503"]You appear not to be applying a valid value to $data['css'] in your controller. [/quote]

Can you provide an example?
#5

[eluser]InsiteFX[/eluser]
I just tried it on my system and it works fine using your directory structure.

Unless you are missing your ending body and html tags!
Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;!-- Le HTML5 shim, for IE6-8 support of HTML elements --&gt;
    &lt;!--[if lt IE 9]>
      [removed][removed]
    <![endif]--&gt;
  &lt;/head&gt;
&lt;body&gt;

<p>&lt;?php echo $css; ?&gt;</p>

&lt;/body&gt;
&lt;/html&gt;
#6

[eluser]jzmwebdevelopement[/eluser]
[quote author="InsiteFX" date="1328596318"]I just tried it on my system and it works fine using your directory structure.

Unless you are missing your ending body and html tags!
Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;!-- Le HTML5 shim, for IE6-8 support of HTML elements --&gt;
    &lt;!--[if lt IE 9]>
      [removed][removed]
    <![endif]--&gt;
  &lt;/head&gt;
&lt;body&gt;

<p>&lt;?php echo $css; ?&gt;</p>

&lt;/body&gt;

&lt;/html&gt;
[/quote]

Thanks so much
#7

[eluser]jzmwebdevelopement[/eluser]
[quote author="InsiteFX" date="1328596318"]I just tried it on my system and it works fine using your directory structure.

Unless you are missing your ending body and html tags!
Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;!-- Le HTML5 shim, for IE6-8 support of HTML elements --&gt;
    &lt;!--[if lt IE 9]>
      [removed][removed]
    <![endif]--&gt;
  &lt;/head&gt;
&lt;body&gt;

<p>&lt;?php echo $css; ?&gt;</p>

&lt;/body&gt;
&lt;/html&gt;
[/quote]

Hey,

I have tried again on a new install and I can pass
Code:
$data
from the main view but I am still getting the error when I try and pass data in my admin view. I have uploaded my code -> https://github.com/jzmwebdevelopment/CI-Structure-.

J
#8

[eluser]InsiteFX[/eluser]
Try this:
Code:
public function index()
{
    $data = array();

    $data['css'] = "css";

    $this->load->vars($data);  // makes it aviable to all views.

    $this->load->view('admin/assets/header');
}
#9

[eluser]jzmwebdevelopement[/eluser]
[quote author="InsiteFX" date="1328647851"]Try this:
Code:
public function index()
{
    $data = array();

    $data['css'] = "css";

    $this->load->vars($data);  // makes it aviable to all views.

    $this->load->view('admin/assets/header');
}
[/quote]

I have tried that with out any luck. Any other ideas, its like its not being seen.
#10

[eluser]CroNiX[/eluser]
Um, in your view (header.php), you are trying to echo $text, which you are not passing to the view. Change it to $css, which you ARE passing Smile




Theme © iAndrew 2016 - Forum software by © MyBB