Welcome Guest, Not a member yet? Register   Sign In
Modular CI uploading problem
#21

[eluser]the_unforgiven[/eluser]
Yes first time I have used MXHMVC too if i would have done like i did before I wouldn't have this problem, but something is stopping it from uploading and saving to database, but i need to find it out.
#22

[eluser]wiredesignz[/eluser]
[quote author="the_unforgiven" date="1362657714"]... if i would have done like i did before I wouldn't have this problem, ...[/quote]

Did you use a model that extends a library class before?
#23

[eluser]TheFuzzy0ne[/eluser]
Yes, it's the simple fact that your validation rules is not being called upon. I'm certain that making the modifications Wiredesignz outlines in his documentation, will solve your problem.

I'm not entirely sure where you're trying to save the data to the database. In my experience, it's usually done from within the controller when validation passes. In your case, validation will pass anyway, since the rule is not being called (because it can't find the method), it's quietly ignored by the validation library.

EDIT: Oh, hey, WD. Smile
#24

[eluser]the_unforgiven[/eluser]
The man himself!!

Maybe you can help me!

Would you read the 1st thread so you can see where am at
#25

[eluser]the_unforgiven[/eluser]
Code:
public function form($id = '')
{
  if ($this->input->post('btn_cancel'))
  {
   redirect('portlets');
  }

  $this->form_validation->set_rules('title', 'Title', 'required|trim');
  $this->form_validation->set_rules('userfile', 'Image', 'callback__do_upload_file|trim');

  //IF validation passes save to DB
  if ($this->wc_portlets->run_validation())
  {
   $id = $this->wc_portlets->save($id);
   redirect('portlets/index/' . $id);

  }
  
  if ($id and !$this->input->post('btn_submit'))
  {
   $this->wc_portlets->prep_form($id);
  }

  $this->layout->buffer('content', 'portlets/form');
  $this->layout->render();
}


MY_Model to save has two functions to do what is detailed above.
Code:
public function run_validation($validation_rules = NULL)
{
  if (!$validation_rules)
  {
   $validation_rules = $this->default_validation_rules;
  }

  foreach (array_keys($_POST) as $key)
  {
   $this->form_values[$key] = $this->input->post($key);
  }

  if (method_exists($this, $validation_rules))
  {
   $this->validation_rules = $validation_rules;

   $this->load->library('form_validation');

   $this->form_validation->set_rules($this->$validation_rules());

   $run = $this->form_validation->run();

   $this->validation_errors = validation_errors();

   return $run;
  }
}

public function save($id = NULL, $db_array = NULL)
{
  if (!$db_array)
  {
   $db_array = $this->db_array();
  }

  if (!$id)
  {
   if ($this->date_created_field)
   {
    $db_array[$this->date_created_field] = date('Y-m-d H:i:s');
   }

   $this->db->insert($this->table, $db_array);

   return $this->db->insert_id();
  }
  else
  {
   if ($this->date_modified_field)
   {
    $db_array[$this->date_modified_field] = date('Y-m-d H:i:s');
   }

   $this->db->where($this->primary_key, $id);
   $this->db->update($this->table, $db_array);

   return $id;
  }
}




Theme © iAndrew 2016 - Forum software by © MyBB