Thread

{AID:class:method} not working

December 15, 2011 11:39am

Subscribe [4]
  • #1 / Dec 15, 2011 11:39am

    IOS Admin

    33 posts

    I found a reference to an AID tag that should return the Action ID of the specified class and method. However with I add this tag to a template it does not get replaced.

    Does this tag have to be nested in another tag? Must the user be logged in? Where are the doc for this tag?

  • #2 / Dec 16, 2011 7:31pm

    Sean C. Smith's avatar

    Sean C. Smith

    3818 posts

    Hi IOS Admin,

    I am unfamiliar with this tag, could you show me the reference? Is this an ExpressionEngine tag or a CodeIgniter tag?

    Sean

  • #3 / Dec 17, 2011 12:46pm

    IOS Admin

    33 posts

    See: http://ellislab.com/expressionengine/user-guide/development/reference/functions.html

    fetch_action_id(class [str], method [str]) Returns a properly formated action id tag Class: Functions (functions) Description: Modules have certain actions for forms, links, etc. that are recognized via an action ids that are inserted into the database upon installation of that module. This function returns a tag in the format {AID:class:method} for use in the frontend. (See also EE->cp->fetch_action_id). $action_id = $this->EE->functions->fetch_action_id(‘Comment’, ‘insert_new_comment’);
  • #4 / Dec 18, 2011 7:15am

    Sean C. Smith's avatar

    Sean C. Smith

    3818 posts

    IOS Admin,

    I am unfamiliar with add-on development myself, but will bring this thread to the attention of a developer and another support tech who is familiar with add-on development.

  • #5 / Dec 19, 2011 11:30am

    Robin Sowell's avatar

    Robin Sowell

    12730 posts

    You won’t typically add the tag itself- but basically- http://ellislab.com/expressionengine/user-guide/development/reference/functions.html#fetch-action-id-class-str-method-str :

    $id = $this->EE->functions->fetch_action_id('Search', 'do_search');

    So you pass it the class and method- it generates the tag- if used in a template, the tag is replaced by the action id number- which is typically used in a form and when EE spots ACT=”5” it figures out the class and method that should be triggered by that call.

    But yes- in development, you’d pretty much never use the tag itself. Still- manually create one with a proper/existing class/method and it will output it. So: {AID:Search:do_search} in a template will come back with the id for that class/method combo from the exp_actions table.

    Did that help? Also- shifting to development as I suspect it’s more in line with how you’d need to use this one.

  • #6 / Dec 19, 2011 12:22pm

    IOS Admin

    33 posts

    Hey Robin. Thanks for the reply. I understand your post and was expecting as such. But the tag does not seem to be working for me. I even tried the tag {AID:Search:do_search} as you stated in your post. All I get is the tag code displayed. It is not being parsed.

    Does it only work within another tag such as the entries tag? I am guessing not, but I don’t know where else to look. It should be straight forward. Put the tag in the template and the action id should display when parsed. I am wanting to use this with my own custom module but that shouldn’t be an issue and testing using the do_search tag shows the problem not to be unique to my module.

    Any other ideas?

  • #7 / Dec 19, 2011 1:05pm

    Robin Sowell's avatar

    Robin Sowell

    12730 posts

    Hrm- curious. It won’t be parsed if it can’t pull back an action id for the specified class/method pair. They SHOULD be in the db- upper-case class, lower-case method. Make sure the search module is installed- then flip ‘Display output profiler’ on in ‘Admin- System Admin- Output and Debug’. Take a look at the queries. Typically the last one gathers up all of the action ids and then the template parser subs them in. So with just that ‘faked’ tag on a template, I have as my last displayed query

    SELECT action_id, class, method FROM exp_actions WHERE (class= 'Search' AND method = 'do_search')

    And in my case- I see a ‘33’ displayed on the page- which is the relevant action id.

  • #8 / Dec 19, 2011 1:22pm

    Robin Sowell's avatar

    Robin Sowell

    12730 posts

    Ah- I see. With just the tag, the id isn’t added to $this->action_ids- hence may not be parsed. Try it with php turned on in the template and action calling fetch_action_id - which gets it in $this->action_ids and ensure the template will swap it out.

    <?php
    
    $id = $this->EE->functions->fetch_action_id('Search', 'do_search');
    
    echo $id;
    
    ?>

    And at this point I realize- this may not actually be helping you with the actual problem. Like I say- I can’t think when you’d actually use the tag, it’s more an automatic intermediate step to getting the action id. The way it works means a single query can be used to replace all of the ids at once, rather than a separate query for each id.

    How are you using the fetch_action_id that’s not working/parsing for you? The most obvious reason will be if there isn’t a class/method match in the database.

  • #9 / Dec 19, 2011 1:54pm

    IOS Admin

    33 posts

    Well, I am actually looking to not have to use PHP or the fetch_action_id.

    All I was looking for is a way for referencing the appropriate action id in a template without hard-coding it.

    In my case, my module has an action that I will be posting to via AJAX. So, I need the ACT=ID in the POST URL. I could hard-code it but I thought it would be better to have the system grab the correct ID, since it is theoretically possible for the ID to change. In my case my module is a single use internal module that won’t be shared so I should know when and if the action id would change but I thought I could make things easier to maintain if I could use a built-in tag. When I saw a reference to the AID tag I thought that might be the proper thing to use. Doesn’t seem like it is.

    I will probably just create my own tag within my module to accomplish the same thing.

  • #10 / Dec 19, 2011 2:16pm

    Robin Sowell's avatar

    Robin Sowell

    12730 posts

    Ah- I begin to understand. Why not make a tag for the link itself? Take a look at the comment module- mod.comment.php

    function ajax_edit_url()
     {
      $url = $this->EE->functions->fetch_site_index(0, 0).QUERY_MARKER.'ACT='.$this->EE->functions->fetch_action_id('Comment', 'edit_comment');
      
      return $url;
     }

    That’s used in some generated ajax for comment editing, but no reason you couldn’t do something similar and just have a {exp:my_module:ajax_link} that outputs the link.

    Make sense? (And that said- hard coding it isn’t horrible, but if you’ve already got a module, easy enough to add the tag as well.)

  • #11 / Dec 19, 2011 4:25pm

    IOS Admin

    33 posts

    Thanks. That’s what I will do.

    I could see where the {AID} tag may be of use to other though. Maybe this should be added to the feature request queue.

  • #12 / Sep 06, 2017 8:05am

    Frans Cooijmans's avatar

    Frans Cooijmans

    33 posts

    In EE2 the

    {AID:Class:Function}

    has some inconsistent behaviour, it only parses the tag if your addon contains

    ee()->functions->fetch_action_id('Class', 'Function');

    before rendering the template.

ExpressionEngine News

#eecms, #events, #releases