I have a controller that stores the navigation link information in an array. Then I use a foreach statement in my view file to load the link information. I do this so I can easily use a link divider image in my menu. The problem is that I get a CI error saying that an invalid foreach argument has been supplied, even though the code is correct compared to PHP.net’s examples of a foreach. This is my controller code:
$data['links'] = array(
'Home' => '',
'Forum' => $data['url']."/forums/index.php",
'Support' => $data['url']."/support",
'Roster' => $data['url']."/roster",
'Events' => $data['url']."/events",
'Prospects' => $data['url']."/prospects",
'Contact' => $data['url']."/contact"
);
$data['link'] = implode("".$data[", $data['links']);
$data['user'] = array(
'Login' => $data['url']."/login",
'Register' => $data['url']."/register",
'Find Pass' => $data['url']."/login/forgot"
);
$data['welcome'] = "Welcome, guest!";
$data['user'] = implode(" | ", $data['user']);
$this->load->view('overall_header', $data);
This is my view code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=$title; ?></title>
<link rel=stylesheet href='<?=$url; ?>/system/application/views/style.css' /></head>
<body class="twoColElsRtHdr">
<div id="container">
<div id="header">
images/logo.gif
<!-- end #header --></div>
<div id='navigation'>
<?php
foreach($links as $name => $href): ?>
<a href="http://<?=$href"><?=$name; ?></a>
<?php endforeach; ?>
</div>
<div id='usermenu'>
<?=$welcome; ?>
<?php
foreach($user as $name => $href): ?>
<a href="http://<?=$href"><?=$name; ?></a>
<?php endforeach; ?>
</div>
<div id='body'>
Thanks for any help.