Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

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)?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
    
since v2.6 uses new super global: ee()->db->insert('actions', $data); –  Peter Lewis Jun 10 at 14:44
    
Could you submit your updated code as another answer for clarity? –  Andrew Fairlie Jun 10 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 at 19:11
    
Ah, I guess inserting the action to the database directly is the par of course. –  arvinsim Jun 11 at 3:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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