⚠ 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

get_primary_key



Julio
  • profile picture
  • Member

Posted 07 June 2013 - 02:52 AM

Hi everybody!

 

How to use the function get_primary_key?

There's no documentation about it.

Can i use it to get primary key from list state?

 

I would like to get the primary key and use it with add_action. Could it be possible?

 

For example:

$primary_key = $crud->get_primary_key('my_table');
if($primary_key == 1){
        $crud->add_action('Process', '', 'main/process','ui-icon-signal');
}

Thanks.


davidoster
  • profile picture
  • Member

Posted 09 June 2013 - 04:54 AM

The function get_primary_key() function even though is a public function is not needed to be used somewhere within your code.

It's primary function is to return the field that acts as a primary key to a specific table.

If you call it it will return the field (not the value) that acts as a primary key on this table.

 

The above code you wrote is wrong. If you want to use it you have to 

$primary_key = $crud->get_primary_key(); but this line just returns the name of the field (or an array with the names of the primary keys if there are more than one defined on the database).

 

Now for the add_action you ask, just read the documentation again!

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