Welcome Guest, Not a member yet? Register   Sign In
new with codeigniter
#13

[eluser]kiga[/eluser]
this is the code, i'm trying to debug something, but this is my first time with codeigniter and php
Code:
function add(){
        // set validation properties
        $this->_set_fields();
        
        // set common properties
        $data['title'] = 'Add new person';
        $data['message'] = '';
        $data['action'] = site_url('person/addPerson');
        $data['link_back'] = anchor('person/index/','Back to list of persons',array('class'=>'back'));
    
        // load view
        $this->load->view('personEdit', $data);
    }
    
    function addPerson(){
        // set common properties
        $data['title'] = 'Add new person';
        $data['action'] = site_url('person/addPerson');
        $data['link_back'] = anchor('person/index/','Back to list of persons',array('class'=>'back'));
        
        // set validation properties
        $this->_set_fields();
        $this->_set_rules();
        
        // run validation
        if ($this->validation->run() == FALSE){
            $data['message'] = '';
        }else{
            // save data
            $person = array('name' => $this->input->post('name'),
                            'gender' => $this->input->post('gender'),
                            'dob' => date('Y-m-d', strtotime($this->input->post('dob'))));
            $id = $this->personModel->save($person);
            
            // set form input name="id"
            $this->validation->id = $id;
            
            // set user message
            $data['message'] = '<div class="success">add new person success</div>';
        }
        
        // load view
        $this->load->view('personEdit', $data);
    }

Code:
function update($id){
        // set validation properties
        $this->_set_fields();
        
        // prefill form values
        $person = $this->personModel->get_by_id($id)->row();
        $this->validation->id = $id;
        $this->validation->name = $person->name;
        $_POST['gender'] = strtoupper($person->gender);
        $this->validation->dob = date('d-m-Y',strtotime($person->dob));
        
        // set common properties
        $data['title'] = 'Update person';
        $data['message'] = '';
        $data['action'] = site_url('person/updatePerson');
        $data['link_back'] = anchor('person/index/','Back to list of persons',array('class'=>'back'));
    
        // load view
        $this->load->view('personEdit', $data);
    }


Messages In This Thread
new with codeigniter - by El Forum - 04-13-2011, 01:44 PM
new with codeigniter - by El Forum - 04-13-2011, 02:02 PM
new with codeigniter - by El Forum - 04-13-2011, 04:57 PM
new with codeigniter - by El Forum - 04-14-2011, 08:47 AM
new with codeigniter - by El Forum - 04-14-2011, 11:07 AM
new with codeigniter - by El Forum - 04-14-2011, 02:11 PM
new with codeigniter - by El Forum - 04-14-2011, 03:39 PM
new with codeigniter - by El Forum - 04-14-2011, 03:43 PM
new with codeigniter - by El Forum - 04-14-2011, 04:02 PM
new with codeigniter - by El Forum - 04-14-2011, 04:07 PM
new with codeigniter - by El Forum - 04-14-2011, 04:14 PM
new with codeigniter - by El Forum - 04-14-2011, 04:17 PM
new with codeigniter - by El Forum - 04-14-2011, 04:29 PM
new with codeigniter - by El Forum - 04-14-2011, 04:43 PM
new with codeigniter - by El Forum - 04-14-2011, 04:55 PM
new with codeigniter - by El Forum - 04-14-2011, 06:43 PM
new with codeigniter - by El Forum - 04-14-2011, 08:52 PM
new with codeigniter - by El Forum - 04-15-2011, 12:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB