For some reason I’m getting an undefined variable on the view and not quite sure why. When I do a print_r of the variable of footer_links it shows up fine as such:
Array ( [0] => stdClass Object ( [link_name] => Home [short_name] => index ) 1 => stdClass Object ( [link_name] => About Us [short_name] => about-us ) [2] => stdClass Object ( [link_name] => Site Map [short_name] => site-map ) [3] => stdClass Object ( [link_name] => Contact-Us [short_name] => contact-us ) [4] => stdClass Object ( [link_name] => News Feed [short_name] => news-feed ) )
I know I’m not passing the variable in but when I tried it with the build it didn’t work. Not sure why I should be passing it in. I’m using Phil Sturgeon’s template library.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: footer_links
Filename: v1/footer.php
Line Number: 4
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: v1/footer.php
Line Number: 4
Controller:
$activeTemplate = $this->kow->getTemplate();
$siteInfo = $this->kow->getSiteTitleAndSlogan();
$footer_links = $this->kow->getFooterNav();
$this->template
->title($siteInfo[0]->site_name,$siteInfo[0]->site_slogan)
->prepend_metadata('<link rel="stylesheet" type="text/css" href="http://www.kansasoutlawwrestling.com/assets/css/'.$activeTemplate[0]->short_name.'.css" />')
->set_partial('header', $activeTemplate[0]->short_name.'/header')
->set_partial('footer', $activeTemplate[0]->short_name.'/footer')
->build('kow');
View:
<div id="footer">
<ul>
<?php foreach($footer_links as $row)
{
?>
<li><a><?php echo $row->link_name; ?></a></li>
<?php
}
?>
</ul>
<p>©COPYRIGHT 2010 ALL RIGHTS RESERVED</p>
</div>
EDIT:
I found this stackoverflow question which is the same sort of deal I’m working with.
Creating Dynamic Links Through DB and CI
Controller:
$activeTemplate = $this->kow->getTemplate();
$siteInfo = $this->kow->getSiteTitleAndSlogan();
$footer_links['rows'] = $this->kow->getFooterNav();
$this->template
->title($siteInfo[0]->site_name,$siteInfo[0]->site_slogan)
->prepend_metadata('<link rel="stylesheet" type="text/css" href="http://www.kansasoutlawwrestling.com/assets/css/'.$activeTemplate[0]->short_name.'.css" />')
->set('footer', $footer_links)
->set_partial('header', $activeTemplate[0]->short_name.'/header')
->set_partial('footer', $activeTemplate[0]->short_name.'/footer')
->build('kow');
Model:
function getFooterNav()
{
$this->db->select('site_menu_structures_links.link_name,site_menu_structures_links.short_name');
$this->db->from('site_menu_structures_links');
$this->db->join('site_menu_structures', 'site_menu_structures.id = site_menu_structures_links.menu_structure_id');
$this->db->where('site_menu_structures.short_name', 'footernav');
$query = $this->db->get();
return $query->result_array();
}
View:
<div id="footer">
<ul>
<?php foreach($rows as $row)
{
?>
<li><a><?php echo $row->link_name; ?></a></li>
<?php
}
?>
</ul>
<p>©COPYRIGHT 2010 ALL RIGHTS RESERVED</p>
</div>
I’m not familiar with the template engine you’re using but how are you passing your variable to your view? Are you doing the
print_rinside the controller (of course here it will show) or view? Try puttingvar_dump($footer_links); exit;as the first line in your footer.php file.