Site Cloner PHP Script
Bargain Hunter PHP Script
Job Hunter PHP Script
Site Login and Access Control PHP Script

Although various books and websites have sections about CRUD for Codeigniter, getting it to work as desired could be a completely different story. I had tried using several premade shortcuts and aborted the mission since modifying the codes was more work than rolling out my own.

Below, is an example of my controller which can be used to create, read, update and delete files. Although this can take a little work, the results are a sigfnificant codebase to use for various applications from making any text editable to blogs. After the following code is used used to make a controller, separate ´view´ files can be made to create, read, update and delete entries from the mysql database.

The files below shows a real working example for which files you may want to add for an application. The code below works without logging in. If you wanted to make certain content acessible upon admin login you would add an ´if login()´ and redirect code to any function in this controller, or to the index function.

class mycrud extends Controller {
    function index() {
        // Check if form is submitted
        if ($this->input->post(‘submit’)) {
            $title = $this->input->xss_clean($this->input->post(‘title’));
            $content = $this->input->xss_clean($this->input->post(‘content’));
            // Add the post
           $this->load->model(‘myposts_model’);
//$this->myposts_model->addPost($title, $content);
$this->db->query(“INSERT INTO `myposts` (title, content)VALUES (‘$title’, ‘$content’)”);
        }
        $this->load->view(‘mycrud/myheader’);
        $this->load->view(‘mycrud/mycrud_view’);
$this->load->view(‘footer’);
    }
function readallentries()
{
   $this->load->helper(‘url’);
$data[‘title’] = “My Page Title”;
$data[‘content’] = “My Page Heading”;
$data[‘query’] = $this->db->get(‘myposts’);
$this->load->view(‘mycrud/myheader’);
$this->load->view(‘mycrud/read_all’, $data);
$this->load->view(‘footer’);
}
function readoneentry()
{
   $this->load->helper(‘url’);
$this->load->view(‘mycrud/myheader’);
$this->db->where(‘id’, $this->uri->segment(3));
$data[‘query’] = $this->db->get(‘myposts’);
$this->load->view(‘mycrud/read_one’, $data);
$this->load->view(‘footer’);
}
function updateall() {
    $id =/* 11*/ $this->uri->segment(3);
    if ($this->input->post(‘submit’)) {
/*$id = ’11’;*/
   $title = $this->input->xss_clean($this->input->post(‘title’));
        $content = $this->input->xss_clean($this->input->post(‘content’));
  $this->db->query(“UPDATE `myposts` SET title=’$title’, content=’$content’ where id=$id “);
$this->load->view(‘mycrud/myheader’);
$this->load->view(‘footer’);
    } else {
        $data = array(‘id’ => $id);
$this->load->view(‘mycrud/myheader’);
        $this->load->view(‘mycrud/update’, $data);
$this->load->view(‘footer’);
    }
}
}