开发者

Expression Engine fetch_action_id() not parsing

So I have tried to get the action ID two ways:

$ACT_ID = $this->EE->func开发者_运维百科tions->fetch_action_id("classname", "function");
$ACT_ID = $FNS->fetch_action_id("classname", "function");

but, it still gives me this as the output:

{AID:classname:function} 

and it doesn't parse it when its output into the view. Is there something else I need to do?


For EE2, there are 2 ways of getting an ACT ID, depending on where you're going to use it.

If you're using it in the font-end / templates, use $this->EE->functions->fetch_action_id('class', 'method');, which will return {AID:class:method} in the template, which the template parser in turn will replace with the actual ACT ID. This is done for performance reasons; only 1 query for all ACT IDs is needed. If no valid ACT ID is found, the AID string will remain as is in the template.

If you're using it in the back-end / Control Panel, use $this->EE->cp->fetch_action_id('class', 'method');, which returns the actual ACT ID. The $this->EE->cp object is only available in the Control Panel (for example, the mcp.your_module.php file). If no valid ACT ID is found, it will return FALSE.


There is an undocumented method "insert_action_ids" in the Functions library that parses action_id's in the templates. So from your addon, if you want to simply have the action ID number, you can do the following:

$ACT_ID = $this->EE->functions->insert_action_ids($this->EE->functions->fetch_action_id('classname', 'method'));

Update

I should add that this method will work anywhere - frontend as well as in the CP. But as some have mentioned, when in the templates it is best for performance to use the "insert_action_ids" method and have the template parser replace these with the correct action IDs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜