Hello :)
i would like to display an Age in the main lsit view of my table, while having only a 'birthday' in the database table, and so a Date field in the Edit and AddNew view
i am able to change the settings for the list view with the field name "Age" with :
$crud->display_as('birthdate', 'Age')
and so compute the age and replace the date, in this column for the "list view" with :
$crud->callback_column('birthdate',array($this,'_callback_birthday'));
and so a private method to calculate an age from a date (remember i have birthday date in database)
i would like to have this 'Age' name as field in the list view, but then go back to a label like 'Birthdate'
so my question : is it possible to change the display_as just for the Add and Edit views ?
public function _callback_birthday($value, $row)
{
// i fight a lot because sometimes people write (m-d-Y) but it is not SQL compatible => (yyyy-mm-dd)
$age = '';
$happyBirthday = '';
$dob = $value;
if(!empty($dob)) {
$birthdate = new DateTime($dob);
$today = new DateTime('today');
$age = $birthdate->diff($today)->y; // date_diff(date_create($value'), date_create('today'))->y;
if (date('m-d') == $birthdate->format('m-d')) {
$happyBirthday = "happy birthday";
}
}
return $age . ' ' . $happyBirthday
}
thank you for your help :)