Welcome Guest, Not a member yet? Register   Sign In
Using segment 3 and 4
#1

[eluser]hungryhippo[/eluser]
Hey guys

I am relatively new to CI and I am trying to get different things to display on screen depending on value the 3rd segment holds. This is what I have done so far and it doesnt seem to work. It completely bypasses my if/else conditions. Any suggestions as to what I am doing wrong?

Code:
// method displays $page form the url
public function view($page)
{
  // if segment 3 and 4, then load model to display products
  if ( ($this->uri->segment(3)) && ($this->uri->segment(4)) )
  {
   // load model for displaying individual products
   //$this->load->model('Products_model');
  
  }
  
  // if only segment 3, display page placeholder image
  elseif ($this->uri->segment(3))
  {
   // display heading and image depending on what value segment 3 holds
   if ($this->uri->segment(3) == 1)
   {
    $data['heading'] = '<h1>Casualwear</h1>';
    $data['image'] = "<img id='clothingImg' src='images/fox_jeans.jpg' height='320px' width='750px' alt='Fox Jeans' />";
    
    //$this->load->view('includes/header.php', $data);
    //$this->load->view($page, $data);
    //$this->load->view('includes/footer.php');
   }
   elseif ($this->uri->segment(3) == 2)
   {
    $data['heading'] = '<h1>MTB Gear</h1>';
    $data['image'] = "<img id='clothingImg' src='images/transition_banner.jpg' height='320px' width='750px' alt='Fox Transition Helmets' />";
   }
  
   $this->load->view('includes/header.php', $data);
   $this->load->view('products', $data);
   $this->load->view('includes/footer.php');
  }
  
  // carry on as normal if no segments
  else
  {
   // carry on as normal
  }
  
  // will pull data form the database to insert in to header, but for now this will do
  $data['title'] = ucfirst($page);
  $data['description'] = "Riders Depot - Aucklands home of actionsports lifestyle and casualwear, mountain biking apparel and accessories";
  
  $this->load->view('includes/header.php', $data);
  $this->load->view($page, $data);
  $this->load->view('includes/footer.php');
} // view function ends here


Messages In This Thread
Using segment 3 and 4 - by El Forum - 08-24-2012, 05:35 PM
Using segment 3 and 4 - by El Forum - 08-25-2012, 12:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB