Reputation: 2234
I'm using GroceryCrud for save data. User register is from website itself. When select their sex, i'm saving 1 for male, 2 for female. Database field is tinyint. So problem is, when admin view their data from backend, it's obvious 1 or 2 will appear on Sex field. How to change it into male, female depending on value?
Upvotes: 1
Views: 2006
Reputation: 1
For edit view use this call back function:
$c->callback_edit_field('sex',array($this,'_callback_sex_edit'));
public function _callback_sex_edit($value){
switch ($value) {
case "1":
return '<input type="radio" name="sex" value="1" checked="checked"/> Female
<input type="radio" name="sex" value="2" /> Male';
break;
case "2":
return '<input type="radio" name="sex" value="1"/> Female
<input type="radio" name="sex" value="2" checked="checked"/> Male';
break;
default:
return '<input type="radio" name="sex" value="1"/>Female
<input type="radio" name="sex" value="2"/> Male';
}
}
Upvotes: 0
Reputation: 3259
You can use the callback_column for this.
In your case you can do:
public function webpages()
{
$c = new grocery_CRUD();
$c->set_table('users');
$c->columns('firstname','lastname','sex','age');
$c->callback_column('sex',array($this,'_callback_sex'));
$output = $c->render();
$this->_view_output($output);
}
public function _callback_sex($value, $row)
{
if ($value == '2') {
return 'male'
} elseif ($value == '1') {
return 'female';
} else {
return "-";
}
}
Upvotes: 2