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

[eluser]doubleplusgood[/eluser]
Hi there,

I'm attempting to use the HTML Helper to add meta tags to my view. However, the page is reporting the following error;

Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined variable: meta
Filename: views/welcome_message.php
Line Number: 2

My welcome.php controller looks like this;
Code:
<?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->view('welcome_message');
        
        $meta = array(
                array('name' => 'robots', 'content' => 'no-cache'),
                array('name' => 'description', 'content' => 'My Great Site'),
                array('name' => 'keywords', 'content' => 'love, passion, intrigue, deception'),
                array('name' => 'robots', 'content' => 'no-cache'),
                array('name' => 'Content-type', 'content' => 'text/html; charset=utf-8', 'type' => 'equiv')
        );
        
        $link = array(
                  'href' => 'css/printer.css',
                  'rel' => 'stylesheet',
                  'type' => 'text/css',
                  'media' => 'print'
        );
    }
}

/* End of file welcome.php */
/* Location: ./base/yourappname/controllers/welcome.php */

And at the head of my welcome_message.php view looks like this;
Code:
<?php echo doctype('html5'); ?>
<?php echo meta($meta); ?>
<head>
<title>Welcome to CodeIgniter</title>
<?php echo link_tag($link); ?>

I would be grateful if someone could point out the (probably obvious) error that I'm making. Big Grin

Thanky.
#2

[eluser]SitesByJoe[/eluser]
Are you sure you loaded the helper? It's not loaded by default.
#3

[eluser]doubleplusgood[/eluser]
Heya,

Yes, the helper is loaded in the autoload.php;
Code:
$autoload['helper'] = array('html');
#4

[eluser]SitesByJoe[/eluser]
And I don't supposed there's any chance that something else stupid is happening, like wrong permissions on the helper file, you've checked the logs to se if they're showing any clues.... that sure is weird.
#5

[eluser]doubleplusgood[/eluser]
The helper does seem to be working because it is putting the html5 doctype into the view. There just seems to be an issue with the meta and link variables. :S
#6

[eluser]SitesByJoe[/eluser]
Hmmm...everything looks fine. Looks like you need to try a couple simple tests to make sure the meta and link functions work AT ALL...
#7

[eluser]LuckyFella73[/eluser]
Did you try to load the view file after declaring the two arrays?

I use to load my views this way:

Code:
$this->load->view('view_example', $data);

I'm not sure if the view file is able to "see" your arrays
the way you are loading the view. Maybe you have to assign
the arrays to a $data array and load the view like wiritten on top
of this post.
#8

[eluser]doubleplusgood[/eluser]
The meta function seems to work if i just do the following in the view;
Code:
<?php echo meta('description', 'My Great site'); ?>

but fails when I do this;
Code:
<?php echo meta($meta); ?>
#9

[eluser]doubleplusgood[/eluser]
[quote author="LuckyFella73" date="1252181655"]Did you try to load the view file after declaring the two arrays?[/quote]

Tried that too, but seemingly the same problem. Sad
#10

[eluser]LuckyFella73[/eluser]
I didn't test this, but maybe this works

Code:
<?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {        
        $data['meta'] = array(
                array('name' => 'robots', 'content' => 'no-cache'),
                array('name' => 'description', 'content' => 'My Great Site'),
                array('name' => 'keywords', 'content' => 'love, passion, intrigue, deception'),
                array('name' => 'robots', 'content' => 'no-cache'),
                array('name' => 'Content-type', 'content' => 'text/html; charset=utf-8', 'type' => 'equiv')
        );
        
        $data['link'] = array(
                  'href' => 'css/printer.css',
                  'rel' => 'stylesheet',
                  'type' => 'text/css',
                  'media' => 'print'
        );
        
        $this->load->view('welcome_message', $data);
    }
}

/* End of file welcome.php */
/* Location: ./base/yourappname/controllers/welcome.php */




Theme © iAndrew 2016 - Forum software by © MyBB