Welcome Guest, Not a member yet? Register   Sign In
passing data to the view
#16

[eluser]Cristian Gilè[/eluser]
It's a very bad practice putting functions inside view. Here, a more elegant solution:

in your controller:
Code:
class Dashboard extends Controller {

function Dashboard()
{
parent::Controller();
}

function index()
{
$data['controller_name'] = $this->router->fetch_class();
$data['links'] = array('Dashboard','link1','link2','link3'); //and so on. You can get them from your model

$this->load->view('header');
$this->load->view('header_bg');
$this->load->view('navigation_bg',$data);
$this->load->view('main');
$this->load->view('future');
$this->load->view('footer_bg');
}
}

in your view:
Code:
<div id="navigation-bg">
  &lt;!--Navigation Part Starts --&gt;
  <div id="navigation">
    <ul class="mainMenu">
&lt;?php
foreach($links as $link)
{
  if(strtolower($link) == strtolower($controller_name))
  {
    $attributes = array('title' => $link, 'class' => 'your_link_class');
  }
  else
  {
    $attributes = array('title' => $link);
  }
  
  echo '<li>'.anchor($link, $link, $attributes).'</li>';
}
?&gt;
</ul>
    <a href="#" class="signup" title="signup now"></a>
    <br class="spacer" />
    <ul class="subNav">
      <li class="noBg"><a href="#" title="Our Benefits">Our Benefits</a></li>
      <li><a href="#" title="What Our Future Plans">What Our Future Plans</a></li>
      <li><a href="#" title="Our Success">Our Success</a></li>
      <li><a href="#" title="Ratings">Ratings</a></li>
      <li><a href="#" title="Latest Blogs">Latest Blogs</a></li>
      <li><a href="#" title="News">News</a></li>
      <li><a href="#" title="Testimonials">Testimonials</a></li>
      <li><a href="#" title="Comments">Comments</a></li>
    </ul>
    <br class="spacer" />
  </div>
  &lt;!--Navigation Part Ends --&gt;
</div>
&lt;!--Navigation Background Part Ends --&gt;


Messages In This Thread
passing data to the view - by El Forum - 01-06-2011, 09:20 PM
passing data to the view - by El Forum - 01-06-2011, 09:25 PM
passing data to the view - by El Forum - 01-06-2011, 11:24 PM
passing data to the view - by El Forum - 01-07-2011, 12:44 AM
passing data to the view - by El Forum - 01-07-2011, 01:07 AM
passing data to the view - by El Forum - 01-07-2011, 05:52 AM
passing data to the view - by El Forum - 01-07-2011, 08:46 AM
passing data to the view - by El Forum - 01-07-2011, 08:47 AM
passing data to the view - by El Forum - 01-07-2011, 09:01 AM
passing data to the view - by El Forum - 01-07-2011, 09:06 AM
passing data to the view - by El Forum - 01-07-2011, 09:11 AM
passing data to the view - by El Forum - 01-07-2011, 04:41 PM
passing data to the view - by El Forum - 01-07-2011, 05:18 PM
passing data to the view - by El Forum - 01-07-2011, 05:59 PM
passing data to the view - by El Forum - 01-07-2011, 06:57 PM
passing data to the view - by El Forum - 01-07-2011, 07:38 PM
passing data to the view - by El Forum - 01-07-2011, 07:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB