2

see this article of the website of grocery-crud:

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)

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

Regards,

Ralph

Ralph Schipper
  • 701
  • 2
  • 12
  • 24

1 Answers1

4

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..

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 e.g $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('city','country','phone','smiley');

hope u find this useful.

Amin Adha
  • 317
  • 3
  • 11
  • yeah verry usefull, you give me 2 options, great, I'll take look tomorrow. Thanks a lot man, I preciate that – Ralph Schipper Nov 28 '13 at 19:41
  • 1
    One thing I would add to this answer is make sure you put an underscore (`_`) at the beginning of your callback name, so that it isn't accessible from a URL (e.g. `_just_a_test`). – Alex W Mar 13 '14 at 13:55