Welcome Guest, Not a member yet? Register   Sign In
Link Info, Arrays, and Foreach
#1

[eluser]Bl4cKWid0w[/eluser]
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:

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("<img src='".$data[' width='36' height='36' alt='&nbsp;' border='0'>", $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("&nbsp;|&nbsp;", $data['user']);
        $this->load->view('overall_header', $data);

This is my view code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;?=$title; ?&gt;&lt;/title&gt;
&lt;link rel=stylesheet href='&lt;?=$url; ?&gt;/system/application/views/style.css' /&gt;&lt;/head>

&lt;body class="twoColElsRtHdr"&gt;

<div id="container">
  <div id="header">
    <img src="images/logo.gif" width="437" height="130" alt="Fourth Core" />
&lt;!-- end #header --&gt;</div>
  
  <div id='navigation'>
    &lt;?php
    foreach($links as $name => $href): ?&gt;
    <a href='&lt;?=$href; ?&gt;'>&lt;?=$name; ?&gt;</a>
    &lt;?php endforeach; ?&gt;
  </div>
        
  <div id='usermenu'>
      &lt;?=$welcome; ?&gt;<br />
    &lt;?php
    foreach($user as $name => $href): ?&gt;
    <a href='&lt;?=$href; ?&gt;'>&lt;?=$name; ?&gt;</a>
    &lt;?php endforeach; ?&gt;
  </div>
    
  <div id='body'>

Thanks for any help.


Messages In This Thread
Link Info, Arrays, and Foreach - by El Forum - 12-25-2008, 01:41 AM
Link Info, Arrays, and Foreach - by El Forum - 12-26-2008, 12:40 AM
Link Info, Arrays, and Foreach - by El Forum - 12-26-2008, 01:54 AM
Link Info, Arrays, and Foreach - by El Forum - 12-26-2008, 04:58 AM
Link Info, Arrays, and Foreach - by El Forum - 12-26-2008, 06:56 PM
Link Info, Arrays, and Foreach - by El Forum - 12-26-2008, 07:12 PM
Link Info, Arrays, and Foreach - by El Forum - 12-26-2008, 10:24 PM
Link Info, Arrays, and Foreach - by El Forum - 12-27-2008, 03:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB