⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

how to customize add and show data ?



ali_fattahi
  • profile picture
  • Member

Posted 24 February 2012 - 18:51 PM

Hello
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

ali_fattahi
  • profile picture
  • Member

Posted 26 February 2012 - 21:43 PM

nobody were to answer my question after 2 days ? :blink:

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 26 February 2012 - 23:00 PM

Hello Ali , welcome to the forum and sorry for the delayed answer.

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.

ali_fattahi
  • profile picture
  • Member

Posted 27 February 2012 - 06:52 AM

Hello Johnny.
Thanks for reply .
Solved my problem with your solution .

Thanks Again