Welcome Guest, Not a member yet? Register   Sign In
Dynamic Routes & Controllers
#1

[eluser]Steve Goodwin[/eluser]
So I'm currently creating a custom CMS, it's nothing special, but I'm getting stuck on a few things. I'm mainly doing this because I'm new to CI and want to be proficient in it so a simple CMS is my first project of choice.

The first problem I've come up against is how do you mix dynamic routing and controllers into the same system?

For example, in my database I have a table for testimonials, the record needs to be in the database for the content on the testimonials page, but I also need this page to utilize my testimonials model and then pass this onto the view in order to loop through and display them on the page.

I'm currently stuck and cannot think of a way to get around this, any suggestions?

My Current Routing file

Code:
$route['default_controller'] = "CMS";
$route['404_override'] = 'CMS';

My CMS Controller

Code:
class CMS extends CI_Controller {

public function index()
{
  // Load Page Model
  $this->load->model('Page');
  
  // Correct Homepage Routing
  $uri = ($this->uri->segment(1)) ? $this->uri->segment($this->uri->total_segments()) : 'home';
  $uri_array = ($this->uri->segment(1)) ? $this->uri->segment_array() : array($uri);
  
  // Varify Route
  $varified = $this->Page->uri_trace($uri_array);
  
  // Check Route Varification
  if($varified)
  {
   // Load Requested Page
   $page = $this->Page->GetPages(array('uri' => $uri));
  
   // Assign Navigation
   $data['utilit_nav'] = $this->Page->get_nav(array('nav' => 'utility'));
   $data['main_nav'] = $this->Page->get_nav(array('nav' => 'main'));
   $data['footer_nav'] = $this->Page->get_nav(array('nav' => 'footer'));
  
   // Assign Page Data
   $data['id'] = $page->c_id;
   $data['parent_id'] = $page->c_pid;
   $data['template'] = $page->c_template;
   $data['uri'] = $page->c_uri;
   $data['background'] = $page->c_background;
   $data['meta_title'] = $page->c_meta_title;
   $data['meta_keywords'] = $page->c_meta_keywords;
   $data['meta_description'] = $page->c_meta_description;
   $data['title'] = $page->c_title;
   $data['content'] = $page->c_content;
   $data['gallery_thumb'] = $page->c_gallery_thumb;
   $data['status'] = $page->c_status;
   $data['order'] = $page->c_order;
   $data['created'] = $page->c_created;
   $data['created_by'] = $page->c_created_by;
  
   // Load Page Template
   $this->load->view('homepage', $data);
  }
  else
  {
   // Page Not Found, Show User 404 Error Page  
   show_404();
  }
}
}

Not sure if this is even the best way to build this kind of system or if the code is in the right place.

I've got several pages which need to work off the initial page in the CMS and then refer to other pages which aren't in the content table, for example my blog will need to use the page from the CMS content table, but anything after /blog/ will need to then utilize the Blog controller in order to get the correct blog article and display it.

Can anyone start by pointing me in the right direction or explaining how you've tackled this problem?





Theme © iAndrew 2016 - Forum software by © MyBB