codeigniter更新方法不起作用

I am new to codeigniter and trying to write an update function to update information in my database. I've gone through a few tutorials but for some reason my code is not working! Any tips or assistance would be greatly appreciated. I'm just testing with two fields right now, name and email, and I get a blank page when I go to my update view.

Here is my model method:

function get_by_id($id){
  return $this->db->get_where('table',array('id'=>$id));
}

function update($id){
 $attributes=array(
    'name'=> $this->input->post('Name'),
    'email'=> $this->input->post('Email')
    );
  return $this->db->where('id',$id)
           ->update('table',$attributes);
}

And here is my relevant controller code:

function edit(){
  $data['row']=$this->Mymodel->get_by_id($id)->result();
  $data['name']= 'Name';
  $data['email']='Email';
  $this->load->view('updateview', $data);
}

function update($id){

  $this->load->model('Mymodel');
  $this->Mymodel->update($id);
  if($this->input->post()){
    redirect('kittens/view/'.$id, 'refresh');
  }

And here is my update view:

<?php echo form_open('kittens/update/')
echo form_hidden('id', $row[0]->id);


foreach($attributes as $field_name){
echo '<p>' . $field_name;
echo form_input($field_name, $row[0]->$field_name) . '</p>';
}
echo form_submit('', 'Update'); 

echo form_close();
?>

Any help would be appreciated! Not sure what specific part is giving me the trouble!

Use the following template:

Controller:

public function updateData(){
....
 $data = array(
  "columnName" => $columnValue
 );
 $whereValue = $someNumber;
 $this->model_name->updateTable($data, $wherevalue);
 ...
}    

Model:

public function updateTable($data, $whereValue){
 $this->db->where('columnName', $whereValue);
 $this->db->update('tableName', $data);
}

the first thing is that the model "MyModel" isn't loaded on the "edit" method in the controller. If you're planning to use that specific model in every function of your controller you should load it in the constructor (so you don't have to load it every time).

Using$this->input->post('Name') in a model is a bad idea. You should receive that data in the controller process it (if you have to) and then send it to the method in the model. I don't know if you can "chain" the db methods like this in codeigniter:

$this->db->where('id',$id)->update('table',$attributes);

try this:

$this->db->where('id',$id);
$this->db->update('table',$attributes);

Hope that helps

  ////////////model for update/////////////
      public function update_customer_contacts($where, $data){

return $this->db->update('customer_contacts', $data, $where);

    }

 ///////////////////update customer///////////////////
  public function update_customer()
    {
              $data = array(
                'company_name'=>$this->input->post('company_name'),
                'address'     =>$this->input->post('address'),
                'telephone'   =>$this->input->post('telephone'),
                'fax'         =>$this->input->post('fax'),
                'email'       =>$this->input->post('email'),
                'website'     =>$this->input->post('website'),
                 );


     $res= $this->customer_model->update_customer(array('customer_id' => $this->input->post('customer_id')), $data);
      ;
     echo json_encode($this->input->post());

    }