简体   繁体   English

食品杂货add_action如何使用pk?

[英]Grocery-crud add_action how to use the pk?

see this article of the website of grocery-crud: 看到杂货网站的这篇文章:

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

for testing I used this line: 为了测试,我使用了以下代码:

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

so when I point my mouse on the smiley I see the adress ..../index.php/test/1 (primary key) 因此,当我将鼠标指向笑脸时,我会看到地址.... / index.php / test / 1(主键)

I have a model with this function: 我有一个具有此功能的模型:

that calls 那个

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

how do I manage to pass that primary key as a variable ? 我如何设法将主键作为变量传递?

It's hard for me to explain, I hope you guys know what I mean. 我很难解释,希望你们知道我的意思。

so I want the pk from the add_function stored so I can use that variable in a model 所以我想存储add_function中的pk,以便可以在模型中使用该变量

Regards, 问候,

Ralph 拉尔夫

You have to use callback function for this.. for example 您必须为此使用回调函数。例如

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

'just_a_test' is callback function.. so i create a function in the same controller like this.. 'just_a_test'是回调函数..所以我在同一个控制器中像这样创建一个函数..

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

you can select any field from your $crud->columns params to replace my $row->id eg $row->country 您可以从$ crud-> columns参数中选择任何字段来替换我的$ row-> id,例如$ row-> country

OR 要么

you can edit existing column like this.. 您可以像这样编辑现有列。

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

and the callback function 和回调函数

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>';
}

dont forget to add 'smiley' in $crud->columns 不要忘记在$ crud-> columns中添加“ smiley”

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

hope u find this useful. 希望你觉得这有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM