• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Page control with dynamic content

#1
[eluser]Unknown[/eluser]
Hey!
In my CI project, I would like to use a full dynamic page control.
So, I've two controller methods, wich are loads the php files.
The model control's queries are based on url segments. All page output generated automatically in the views php file depending on url and results of database, except index.php file.

Is this a right technic/way?

Controller
Code:
public function index()
{
  $data['title'] = "Index";
  $data['nav'] = $this->content_model->get_index_nav(); //TODO
  
  $this->load->view('templates/header', $data);
  $this->load->view('templates/nav', $data);
  $this->load->view('templates/nav_pict', $data);
  $this->load->view('pages/aktualis', $data);
  $this->load->view('templates/footer', $data);
}
public function view($page)
{
  $page = 'content';

  $this->load->helper('text');
  $this->load->helper('url');

  $page = lcfirst(convert_accented_characters(urldecode($page)));

  if ( ! file_exists('application/views/pages/'.$page.'.php'))
  {
   show_404();
  }

  $data['title'] = ucfirst($page); // Capitalize the first letter
  $data['nav'] = $this->content_model->get_nav();
  $data['content'] = $this->content_model->get_content();
  
  if(empty($data['content']))
  {
   show_404();
  }

  $this->load->view('templates/header', $data);
  $this->load->view('templates/nav', $data);
  $this->load->view('pages/'.$page, $data);
  $this->load->view('templates/footer', $data);
}
Model (Each menu has a content in database. When create a new submenu you must be add content)
Code:
public function get_content()
{
   $this->db->select('content.*, mainmenu.label');
   $this->db->from('content');
   $this->db->join('mainmenu', 'mainmenu.id = content.katId', 'left');
   $this->db->where('mainmenu.label', mysql_escape_string(urldecode(end($this->uri->segments))));

   $query = $this->db->get();
  
   return $query->result_array();

}
Routing
Code:
$route['404_override'] = '';
$route['/:any/(:any)'] = 'pages/view/$1';
$route['(:any)'] = 'pages/view/$1';
$route['Index'] = 'pages/index';
$route['default_controller'] = 'pages/index';

Thanks!
Sorry for my bad english


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.