2

请参阅杂货店网站的这篇文章:

http://www.grocerycrud.com/documentation/options_functions/add_action

为了测试我使用了这一行:

$crud->add_action('Smileys', 'http://www.grocerycrud.com/assets/uploads/general/smiley.png', 'test');

因此,当我将鼠标指向笑脸时,我会看到地址 ..../index.php/test/1(主键)

我有一个具有此功能的模型:

那叫

$this->db->where('cust_id', '1');

我如何设法将该主键作为变量传递?

我很难解释,我希望你们知道我的意思。

所以我希望存储 add_function 中的 pk 以便我可以在模型中使用该变量

问候,

拉尔夫

4

1 回答 1

4

你必须为此使用回调函数..例如

$crud->add_action('Smileys', '','','' array($this,'_just_a_test'));

'just_a_test' 是回调函数。所以我在同一个控制器中创建了一个函数,就像这样。

function _just_a_test($primary_key , $row)
{
    return $row->id;
}

您可以从 $crud->columns 参数中选择任何字段来替换我的 $row->id 例如 $row->country

或者

您可以像这样编辑现有列..

$crud->callback_column('smiley', array($this,'_just_a_test2'));

和回调函数

function _just_a_test2($primary_key , $row)
{
    return '<a href="controller/method/'.$row->id.'"><img src="http://www.grocerycrud.com/assets/uploads/general/smiley.png"></a>';
}

不要忘记在 $crud->columns 中添加“笑脸”

$crud->columns('city','country','phone','smiley');

希望你觉得这很有用。

于 2013-11-28T18:16:36.063 回答