Cooper Cooper - 6 months ago 7
HTML Question

How do i use to the input value in the form in the where clause of my model using codeigniter

Want to use the luggage_id in the form input type="text" name="luggage_id" as a where clause in my model to update a row 'status' in 'consignment' table

My view

<form action='<?php echo site_url('clientaccount_ctrl/confirm_load_pickup'); ?>' method='post' name='process'>

<div class="form-group">

<input type="text" class="form-control" name="luggage_id" placeholder="Driver ID">

</div>


</div><!-- /.col -->
<div class="col-sm-4 invoice-col">

<button type="submit" class="btn bg-blue btn-flat margin">CONFIRM PICKUP</button>


</form>


My Controller

public function confirm_load_pickup(){

$this->load->model('Clientaccount_model');
$this->Clientaccount_model->confirm_load_pickup();
redirect('clientaccount_ctrl');

}


My Model

public function confirm_load_pickup(){

$luggage_id = $this->input->post('luggage_id');
$data['status']=3;
$this->db->where('luggage_id',$luggage_id);
$query=$this->db->update('consignment',$data);
return $query;
}

Ray Ray
Answer

I am not an active code ignighter developer, but basic experience with several php mvc frameworks leads me to believe that the model doesn't extend a way to process form data as a controller would.

In the controller scope, $this refers to the controller. In the model scope, $this refers to the model.

Assuming the model scope doesn't explicitly handle the controller scope and post / get methods, it would be unable to process the variable.

So, I would define the input in the controller and inject it into the model

Controller

public function confirm_load_pickup(){
    $luggage_id = $this->input->post('luggage_id');
    $this->load->model('Clientaccount_model');
    $this->Clientaccount_model->confirm_load_pickup($luggage_id);
    redirect('clientaccount_ctrl');
}   

Model

public function confirm_load_pickup($luggage_id){
    $data['status']=3;
    $this->db->where('luggage_id',$luggage_id);
    $query=$this->db->update('consignment',$data);
    return $query;          
}