how to customize add and show data ?
- Single Page
Posted 24 February 2012 - 18:51 PM
I want to add some values to database which is not in insert form .
in other word , when I want to add a new record to database I want to set the value of a field which is not in insert form and I have to calculate the value in background then insert to database . after do this , when I want to show each values in grid I dont want to show orginal value that I inseted in previous step and I want to change the format of the value and show in grids
for example : in insert , I want to inset a date in mktime format that is not in forms and I want to show date format in grids .
in addition I dont want to use form_hidden to hold the values which I dont want to be in forms.
How can I do this ?
Best Regards
Ali
Posted 26 February 2012 - 21:43 PM
Posted 26 February 2012 - 23:00 PM
Actually you simply need the change_field_type and you will add the type named "invisible".
The "invisible" type do exactly this think , it is NOT at add field, it is NOT at edit field , it IS at the column and you can also easily save it with callbacks. Below I have an example for your situation:
function orders_management()
{
$crud = new grocery_CRUD();
$crud->display_as('customerNumber','Customer');
$crud->set_table('orders');
$crud->set_subject('Order');
$crud->change_field_type('orderDate', 'invisible');
$crud->callback_before_insert(array($this,'add_order_date_callback'));
$crud->callback_before_update(array($this,'add_order_date_callback'));
$crud->fields('orderDate','customerNumber');
$output = $crud->render();
$this->_example_output($output);
}
function add_order_date_callback($post_array)
{
$post_array['orderDate'] = date('Y-m-d H:i:s');
return $post_array;
}
At this code if you comment for example the $crud->change_field_type('orderDate', 'invisible'); it will not work . This is just for security reasons so every time you specify which fields will be added. It's a tricky thing and it is not documented so it was good to ask.
Posted 27 February 2012 - 06:52 AM
Thanks for reply .
Solved my problem with your solution .
Thanks Again