CodeIgniter Forums
Message: Undefined variable: meta - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Message: Undefined variable: meta (/thread-22327.html)

Pages: 1 2


Message: Undefined variable: meta - El Forum - 09-05-2009

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


Message: Undefined variable: meta - El Forum - 09-05-2009

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


Message: Undefined variable: meta - El Forum - 09-05-2009

[eluser]doubleplusgood[/eluser]
Heya,

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



Message: Undefined variable: meta - El Forum - 09-05-2009

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


Message: Undefined variable: meta - El Forum - 09-05-2009

[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


Message: Undefined variable: meta - El Forum - 09-05-2009

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


Message: Undefined variable: meta - El Forum - 09-05-2009

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


Message: Undefined variable: meta - El Forum - 09-05-2009

[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); ?>



Message: Undefined variable: meta - El Forum - 09-05-2009

[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


Message: Undefined variable: meta - El Forum - 09-05-2009

[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 */