3

What is the correct way to add a new action to the current list of actions?

Is there a specific EE method to add a new action? Or is it just direct database manipulation(that is, add it via SQL)?

5

Usually it's done on the install method of your addon. Best practice is to take advantage of ActiveRecord and a db->insert:

$data = array(
    'class' => $this->class,
    'method' => $method
);

ee()->db->insert('actions', $data);

You don't need to specify an ACTion ID as this is auto incremented.

You can find a bit more information in the docs for Module Installation.

| improve this answer | |
  • since v2.6 uses new super global: ee()->db->insert('actions', $data); – Peter Lewis Jun 10 '14 at 14:44
  • Could you submit your updated code as another answer for clarity? – Mutual Jun 10 '14 at 14:51
  • Whoops, thanks Peter, well spotted. :) Andrew, Peter has already outlined the updated way of using EE's super global method but I've updated my answer to reflect that. – Ian Jun 10 '14 at 19:11
  • Ah, I guess inserting the action to the database directly is the par of course. – developarvin Jun 11 '14 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.