2013-11-28 45 views
2

看到這篇文章雜貨店污物的網站:Grocery-crud add_action如何使用pk?

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

測試我使用的這條線:

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

所以,當我點我的鼠標上的笑臉我看到ADRESS。 .../index.php的/測試/ 1 (主鍵)

我有此功能的模型:

調用

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

我該如何設法將該主鍵作爲變量傳遞?

我很難解釋,我希望你們知道我的意思。

,所以我想從存儲這樣我就可以使用該變量在模型

關於add_function的PK,

拉爾夫

回答

4

你必須使用回調函數這個..例如

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

'just_a_test'是回調函數..所以我在同一個控制器中創建一個函數,像這樣..

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

您可以從$ crud->列PARAMS選擇任意字段來代替我的$按行> ID如$按行>國家

OR

您可以編輯現有列這樣的。 。

$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-「笑臉」>列

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

希望你發現這很有用。

+0

耶是非常有用的,你給我2個選項,太好了,我明天就去看看。我非常感謝 –

+1

我在這個答案中添加的一件事就是確保在回調名稱的開始處放置一個下劃線('_'),以便它不能從URL訪問(例如' _just_a_test')。 –