[英]Grocery-crud add_action how to use the pk?
看到雜貨網站的這篇文章:
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,以便可以在模型中使用該變量
問候,
拉爾夫
您必須為此使用回調函數。例如
$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中添加“ smiley”
$crud->columns('city','country','phone','smiley');
希望你覺得這有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.