⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Issue with Add_action



Kinetic
  • profile picture
  • Member

Posted 12 December 2014 - 10:11 AM

Hi There,

 

I have recently been introduced to Grocery Crud and am very much enjoying it. 

 

There is an issue I am having as of recent. I have created a custom action but every time the page loads it auto triggers the action. Not only that but it triggers the action for every row, when what i need it to do is post the message specific to that row when the button is clicked. Is there something I am doing wrong or is this some bug?  Thank you ahead.

 

The code: public function post()

{
$this->load->library('facebook'); 
$array = $this->facebook->get_user();
 
$this->load->database();
$this->load->helper('url');
$this->load->library('grocery_CRUD'); 
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('post');
$crud->callback_column('message', array($this, '_full_text'));
 
$crud->add_action('Post', '', '','ui-icon-image',array($this,'_Post'));
$output = $crud->render();
 
$userid = $this->session->userdata('permit');
 
if($userid ){
$this->load->view('home/crudform',$output);  
}else{
redirect('/home/login');
 
}
 
}
 
function _Post($primary_key , $row)
{
 
        return $this->facebook->getPageAccess($row->message);
}
 

 


marlaaragao
  • profile picture
  • Member

Posted 14 June 2015 - 19:35 PM

Hi Kinect, I'm facing the same problem. Did you find a solution? 

 

Thanks!


Nicolás Saiz Arismendi
  • profile picture
  • Member

Posted 28 September 2015 - 14:39 PM

Does anyone know why this happens?


marlaaragao
  • profile picture
  • Member

Posted 21 October 2015 - 10:54 AM

Hi! Sorry for the late response.

 

I don't know WHY it happens, or if it's the desired behavior, but I know that it happens when you have the last parameter (url_callback) set in

 

void add_action( string $label, string $image_url , string $link_url , string $css_class , mixed $url_callback)

 

So, what you have to do is to add your action like this:

$crud->add_action('Label', 'YourImageURL' , 'PathToYourActionFunction', 'CssClass')

and your function must have just one parameter:

function yourFunction($primary_key) { // You don't have the $row parameter
}

This resolved my problem. Good day!


chhatbargaurang
  • profile picture
  • Member

Posted 09 December 2015 - 14:39 PM

Hi Marlaarogao,

 

I am new to this crud and having same problem that you are facing but your solution is not working for me. Can you found why it is occuring or have any other alternative to try?

 

Here is my sample code:

$crud->add_action('Installments', base_url('/assets/images/view.png'), '','',array($this,'open_users_by_agent'));


public function print_installment($primary_key)//,$row){
        // return $this->load->view('printInstallment.php',$row);
        $data['primary_key'] = $primary_key;
       return $this->load->view('printInstallment.php',$data);
}


Above code prints data for every column. Am I doing something wrong? If you have some clue on this topic then please share here.