dousu1900 2013-11-28 15:55
浏览 67
已采纳

Grocery-crud add_action如何使用pk?

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

  • 写回答

1条回答 默认 最新

  • dpfl37651 2013-11-28 18:16
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境