• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to edit record codeigniter CRUD?

#3
Last week we need a decision to use either Zend3 or CI3. In order to test it I used the Zend3 skeleton module which is a simple CRUD project.

here my edit function from the controller
Code:
public function edit($id = NULL)
   {
       
        $data['title']   = "My Album";        
       
        //get the album data
        $data['album']   = $this->albums_model->getByID($id);
        
        $this->form_validation->set_rules('title', 'Title', 'required');
        $this->form_validation->set_rules('artist', 'Artist', 'required');
        
       if ($this->form_validation->run() == FALSE)
       {
            //show the form when not valid
            $this->load->view( get_class($this) . '/add', $data);
       }
       else
       {
            //add the data
            $data = array(
                'title' => $this->input->post('title'),
                'artist' => $this->input->post('artist')
            );
            $this->db->where('id', $id);
            $this->db->update('album', $data);
            redirect('/albums/');
       }

       
   }

And here the function from the model
Code:
public function getByID($id)
    {        
    
        $query = $this->db->get_where('album', array('id' => $id));
        if ( $query->num_rows() > 0){
            return $query->row();
        } else {
            return false;    
        }
    
    }


This is all very simple but hope it helps.

(We did decide to use CI3 rather then Zend)
On the package it said needs Windows 7 or better. So I installed Linux.
Reply


Messages In This Thread
How to edit record codeigniter CRUD? - by ozzy - 06-26-2017, 12:09 PM
RE: How to edit record codeigniter CRUD? - by rtenny - 06-27-2017, 08:13 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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