Welcome Guest, Not a member yet? Register   Sign In
Load different data depending on URL?
#1

[eluser]invision[/eluser]
Hi,

I have a URL: http://www.site.com/index.php/scotland/glasgow/hotels/

I want to do different things depending on what part of the URL the user is visiting.
E.g. if they're on /index.php/scotland/ it'd show different data than when on the full URL above.

How do I achieve this with CodeIgniter?


On a previous thread, I got as far as the following...but it didn't work Sad
I tried to take in the three different parts of the URLs as parameters ($param_1 etc...)

Controller:
Code:
function index($param_1 = FALSE, $param_2 = FALSE, $param_3 = FALSE) {
    //check params to see which are set and act accordingly
    

    // retrieves country
    if (($param_1 !== FALSE) && ($param_2 === FALSE) && ($param_3 === FALSE)) {
      $data['entries'] = $this->Mains->get_entries($param_1);
      $data['title'] = 'country';    
      $data['main'] = 'public_page';
      $this->load->vars($data);
      $this->load->view('template');    
    }

    // retrieves city
    if (($param_1 !== FALSE) && ($param_2 !== FALSE) && ($param_3 == FALSE)) {
      $data['entries'] = $this->Mains->get_entries($param_1, $param_2);
      $data['title'] = 'city';    
      $data['main'] = 'public_page';
      $this->load->vars($data);
      $this->load->view('template');    
    }
    
    // retrieves category
    if (($param_1 != FALSE) && ($param_2 != FALSE) && ($param_3 != FALSE)) {
      $data['entries'] = $this->Mains->get_entries($param_1, $param_2, $param_3);
      $data['title'] = 'category';  
      $data['main'] = 'public_page';
      $this->load->vars($data);
      $this->load->view('template');  
    }      
    
    // no specific category chosen
    if (($param_1 == FALSE) && ($param_2 == FALSE) && ($param_3 == FALSE)) {
      $data['entries'] = $this->Mains->get_entries($param_1, $param_2, $param_3);
      $data['title'] = 'no specific category chosen';  
      $data['main'] = 'public_page';
      $this->load->vars($data);
      $this->load->view('template');  
    }
    
  }


-



-
For reference my Model is:
Code:
<?php
class Mains extends Model {
  function Mains() {
    parent::Model();
  }

  function get_entries($country = FALSE, $city = FALSE, $category = FALSE) {

    $this->db->select('entry.*, city.title as city_title, country.iso3 as country_title, category.title as category_title');
    $this->db->from('entry');
    $this->db->join('category', 'entry.category = category.id');
    $this->db->join('city', 'entry.city = city.id');
    $this->db->join('country', 'city.country = country.iso3');
    if($country !== FALSE) {
      $this->db->where('country.iso3', $country);
    }
    if($city!== FALSE) {
      $this->db->where('city.title', $city);
    }
    if($category!== FALSE) {
      $this->db->where('category.title', $category);
    }
    $result = $this->db->get();
    if($result->num_rows() > 0) {
      return $result->result_array();
    } else {
      return FALSE;
    }
  }
  
  function get_cities($country) {
    $this->db->from('city');
    $this->db->join('country', 'city,country = country.iso3');
    $this->db->where('country.iso3', $country);
    $result = $this->db->get();
  
    if($result->num_rows() > 0) {
      return $result->result_array();
    } else {
      return FALSE;
    }
  }
  
}  
?>


I would massively appreciate any guidance with this.



Many thanks.


Messages In This Thread
Load different data depending on URL? - by El Forum - 10-23-2010, 09:35 AM
Load different data depending on URL? - by El Forum - 10-23-2010, 10:40 AM
Load different data depending on URL? - by El Forum - 10-23-2010, 10:41 AM
Load different data depending on URL? - by El Forum - 10-23-2010, 10:47 AM
Load different data depending on URL? - by El Forum - 10-23-2010, 10:51 AM
Load different data depending on URL? - by El Forum - 10-23-2010, 12:51 PM
Load different data depending on URL? - by El Forum - 10-23-2010, 01:13 PM
Load different data depending on URL? - by El Forum - 10-23-2010, 02:40 PM
Load different data depending on URL? - by El Forum - 10-23-2010, 03:20 PM
Load different data depending on URL? - by El Forum - 10-23-2010, 08:46 PM
Load different data depending on URL? - by El Forum - 10-24-2010, 01:21 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 01:28 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 01:41 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 01:52 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 02:12 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 04:04 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 04:45 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 04:48 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 04:50 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 05:03 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 05:04 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 05:05 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 05:06 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 05:09 AM
Load different data depending on URL? - by El Forum - 10-24-2010, 05:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB