Skip to content

Instantly share code, notes, and snippets.

@jlebrech
Created February 3, 2011 11:02
Show Gist options
  • Save jlebrech/809350 to your computer and use it in GitHub Desktop.
Save jlebrech/809350 to your computer and use it in GitHub Desktop.
in the controller
<?php
function add()
{
$this->setupLayout('Add page',array(),true); // this set's the title, navigation bar, and whether this is an admin view of frontend view
$this->save();
}
function edit($id=null)
{
$this->setupLayout('Edit page',array(),true);
$this->save($id);
}
function save($id=null)
{
// is it a new form..
if (!$this->input->post('posted')){ // have a form_hidden('posted','true') in the view
$this->layout->view('admin/pages/save',array('id'=>$id));
} else {
// validate
$this->form_validation->set_rules('title','Title','required');
if ($this->form_validation->run() == FALSE){
$this->layout->view('admin/pages/save',array('id'=>$id)); // repopulate the form on validation fail
} else {
// save the form through the model
$this->page->save($id);
// go to a thank you page or back to an index
redirect('/admin/pages/manage'); // the index page for the backend is called manage.php as index is alread taken for the frontend
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment