Hi,
I found a problem while using before_insert.
Some value in my field become null when insert to database.
Here is some code in my controller :
$crud->add_fields('from_user_id', 'to_user_id', 'message_content', 'message_status'); $crud->callback_before_insert(array($this,'reply_user'));
function reply_user($value){ if(!empty($value['message_content'])) { $value['from_user_id'] = $this->session->userdata("user_id"); $message_id = substr( current_url(), strrpos( current_url(), '/' )+1 ); $this->load->model('message_model'); $result = $this->message_model->user_get_message($message_id); foreach ($result as $message) { $value['to_user_id'] = $message->from_user_id; } $value['message_status'] = 'Sent'; return $value; } else { echo "false"; } }
Here is the code in my model :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class message_model extends CI_Model { public function user_get_message($message_id){ // $this->db->select('from_user_id'); $this->db->where('message_id', $message_id); $this->db->from('messages'); $query = $this->db->get(); if ($query->num_rows() ==1) { foreach($query->result_array() as $row) { return $query->result(); } } else{ return false; } } }
I already try echo $value['to_user_id']; to see is it null or not.
Well yeah. its not null. I got the value that i want. But when it inserted to database, it become zero value..
Can anyone help me to solve this problem? Pretty new here.