Thanks to your initial posting, I was able to get the dates to save to the DB and not allow the Unix Epoch Date (1/1/1970 GMT, or as I now see it in the USA, 12/31/1969 -8:00 GMT) be saved into the DB and then later displayed, instead of leaving the field empty.
I followed your steps, because I also wanted a date-per-item. My field/column is item_service_date.
I am new to PHP, so do not know if this is the best way to solve this issue, but here are my steps after your steps above.
I added the column to the ip_invoice_items table:
ALTER TABLE invoice
.ip_invoice_items
ADD COLUMN item_service_date
DATE NULL AFTER item_product_id
;
I just started using IP at v1.4.10. (Your code samples have differences, like lang whereas v1.4.10 uses trans)
Then I followed the class-path starting in mdl_items.php
class Mdl_Items extends Response_Model
Which led to application/core/ Response_Model.php
class Response_Model extends Form_Validation_Model
Which led to application/core/ Form_Validation_Model.php
class Form_Validation_Model extends MY_Model
Ending up in application/core/ MY_Model.php where I made the following 3 additions:
- At the top of the file
public $date_created_field;
public $date_modified_field;
public $service_date_field;
Inside the save() function, there are two place to add code. Firstly, for inserting and secondly for updating.
2)
if ($this->service_date_field) {
$service_date = NULL;
if (is_array($db_array)) {
if($db_array[$this->service_date_field]) {
$service_date = date(‘Y-m-d’, strtotime($db_array[$this->service_date_field]));
}
$db_array[$this->service_date_field] = $service_date;
} else {
if ($db_array->{$this->service_date_field}) {
$service_date = date(‘Y-m-d’, strtotime($db_array->{$this->service_date_field}));
}
$db_array->{$this->service_date_field} = $service_date;
}
}
$this->db->insert($this->table, $db_array);
3)
if ($this->service_date_field) {
$service_date = NULL;
if (is_array($db_array)) {
if($db_array[$this->service_date_field]) {
$service_date = date(‘Y-m-d’, strtotime($db_array[$this->service_date_field]));
}
$db_array[$this->service_date_field] = $service_date;
} else {
if ($db_array->{$this->service_date_field}) {
$service_date = date(‘Y-m-d’, strtotime($db_array->{$this->service_date_field}));
}
$db_array->{$this->service_date_field} = $service_date;
}
}
$this->db->where($this->primary_key, $id);
$this->db->update($this->table, $db_array);