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

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?

// 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
  // 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);
   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);
  // carry on as normal if no segments
   // 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);
} // view function ends here

To check whether a var is set or not use isset() (rly good named func) or !empty().

Theme © iAndrew 2016 - Forum software by © MyBB