callback_column不适用于杂货店中的连接表

时间:2013-05-28 12:15:18

标签: codeigniter grocery-crud

我正在尝试使用callback_column函数更改列值。

$crud = new grocery_CRUD();
$crud -> set_table('booking');
//$crud->set_relation('room_id','rooms','name');
$crud->callback_column('room_id',array($this,'_visitor_details_popup')); 

此代码工作正常(_visitor_details_popup函数返回值为room_id

$crud = new grocery_CRUD();
$crud -> set_table('booking');
$crud->set_relation('room_id','rooms','name');
$crud->callback_column('room_id',array($this,'_visitor_details_popup'));

此代码运行良好(room_id未更改)

public function _visitor_details_popup($value, $row)
{

    $visitor_details=explode(',',$value);
    return '<a href="#">Name'.$visitor_details[1].'<a>'.'<div class="popup_content">Address'.$visitor_details[2].'Email'.$visitor_details[3].'</div>;
}

这是杂货店中的一个错误吗?任何棘手的解决方法吗?

1 个答案:

答案 0 :(得分:7)

我有一个技巧。创建一个函数并在callback_column参数上调用它。

$crud = new grocery_CRUD();
$crud -> set_table('booking');
$crud->set_relation('room_id','rooms','name');
$crud->callback_column(unique_field_name('room_id'),array($this,'_visitor_details_popup')); verity 

function unique_field_name($field_name) 
{
    return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin               with a letter and not with a number
}