[eluser]ZioN[/eluser]
Hi,
I have an administration area in which I can dynamicly add or delete 'pages'. But when I want to load the pages I use their ID's. But those look horrible in the url not to mention SEO.
Controller(Site):
Code:
public function page(){
$this->load->model('settings_model');
$this->load->model('pages_model');
$data['pages'] = $this->pages_model->get_page();
$data['settings'] = $this->settings_model->get_settings();
$this->load->view('page_view', $data);
if ($data = $this->pages_model->get_page()){
$this->load->model('settings_model');
$this->load->model('pages_model');
$data['pages'] = $this->pages_model->get_page();
$data['settings'] = $this->settings_model->get_settings();
}
else{
redirect('site');
}
}
Model(pages_model):
Code:
public function get_page(){
$id = $this->input->get('id');
$query = $this->db->get_where('pages', array('id' => $id));
if ($query->num_rows() > 0){
$data = $query->result();
return $data;
}
else{
return false;
}
}
index_view:
Code:
<?php
foreach($settings as $setting){
echo "<title>" . $setting->site_title . " • Settings</title>";
}
foreach($pages as $row){
echo "<ul>";
echo "<li><a id=". $row->id .">". $row->page_title ." ". $row->id ." </a></li>";
echo "</ul>";
}
?>
This is where I create the navigation (for testing purposes it's just an UL and LI)
page_view:
Code:
<?php
foreach($settings as $setting){
echo "<title>" . $setting->site_title . " • Settings</title>";
}
foreach($pages as $row){
echo $row->page_title;
echo $row->content;
echo $row->author;
echo $row->datetime;
}
?>
When I click an item in the navigation it directs me to site/page?id=1 for example. This works fine, but I want to translate the id=1 to the actual "page_title". This would result in site/page/home for example.
PS: I only included relevant code.