Welcome Guest, Not a member yet? Register   Sign In
building an efficient admin control panel
#10

[eluser]Michael Wales[/eluser]
I only called that model based on principle, probably because you would be using it in that controller.

The Admin_pages controller is the controller used to, obviously, administer pages. The pages_m model contains all of our methods that interact with the database. By loading this model within the constructor you save yourself some typing later on.

For instance, if we had a create() method, which created a new page:
Code:
function create() {
  $this->load->library('validation');
  $rules['title'] = 'trim|required|max_length[255]|callback__check_title';
  $rules['body'] = 'trim|required';
  $rules['tags'] = 'trim';
  $rules['btnSave'] = 'required';
  $this->validation->set_rules($rules);
  $fields['title'] = 'Page Title';
  $fields['body'] = 'Page Content';
  $fields['tags'] = 'Tags';
  $this->validation->set_fields($fields);

  if ($this->validation->run()) {
    if ($this->pages_m->createPage($_POST)) {
      // Go view the page
    } else {
      show_error('An unexpected error occurred, please try again.');
    }
  } else {
    $this->load->view('admin/pages/create');
  }
}

In pages_m->createPage I would futher validate my data, ensuring I am only inserting columns I am expecting from this particular form, and then make the database insert.

I guess I strayed from the point - the reason it's there is because you're probably going to use it in every method within this controller. Big Grin


Messages In This Thread
building an efficient admin control panel - by El Forum - 12-05-2007, 12:22 PM
building an efficient admin control panel - by El Forum - 12-05-2007, 12:49 PM
building an efficient admin control panel - by El Forum - 12-05-2007, 01:01 PM
building an efficient admin control panel - by El Forum - 12-05-2007, 01:18 PM
building an efficient admin control panel - by El Forum - 12-06-2007, 02:30 AM
building an efficient admin control panel - by El Forum - 12-06-2007, 03:14 AM
building an efficient admin control panel - by El Forum - 12-06-2007, 07:23 AM
building an efficient admin control panel - by El Forum - 12-06-2007, 09:22 AM
building an efficient admin control panel - by El Forum - 12-06-2007, 09:44 AM
building an efficient admin control panel - by El Forum - 12-06-2007, 10:37 AM
building an efficient admin control panel - by El Forum - 12-06-2007, 12:51 PM
building an efficient admin control panel - by El Forum - 12-06-2007, 07:41 PM
building an efficient admin control panel - by El Forum - 12-07-2007, 02:03 AM
building an efficient admin control panel - by El Forum - 12-07-2007, 08:12 AM
building an efficient admin control panel - by El Forum - 12-07-2007, 08:18 AM
building an efficient admin control panel - by El Forum - 12-07-2007, 08:51 AM
building an efficient admin control panel - by El Forum - 12-07-2007, 09:35 AM
building an efficient admin control panel - by El Forum - 12-07-2007, 09:37 AM
building an efficient admin control panel - by El Forum - 12-07-2007, 09:41 AM
building an efficient admin control panel - by El Forum - 12-07-2007, 08:54 PM
building an efficient admin control panel - by El Forum - 11-23-2010, 06:30 PM



Theme © iAndrew 2016 - Forum software by © MyBB