简体   繁体   English

TYPO3 Extbase-如何从外部调用控制器动作

[英]TYPO3 Extbase - How to call a controller action from external

Lets say I have an extension called my_extension and in the my_extension a plugin called apiResponse . 可以说我有一个扩展名为my_extension ,在my_extension中有一个名为apiResponse的插件。

Then I have in my controller a function called sendApiDataAction . 然后我的控制器中有一个名为sendApiDataAction的函数。

How can I call this sendApiDataAction from external via a usual http GET request? 如何通过通常的http GET请求从外部调用此sendApiDataAction

First, you need these information from your extension: 首先,您需要从扩展程序中获取以下信息:

  • extensionKey (that's easy, in your example it's myExtension ) extensionKey(这很简单,在您的示例中是myExtension
  • pluginName (that's the name you defined in your ext_localconf.php where you assign the actions) pluginName(这是您在ext_localconf.php中定义操作的名称)
  • actionName (in your example sendApiData - without the action ) actionName(在您的示例sendApiData -没有action
  • controllerName (that's the controller where your action is) controllerName(这是您的操作所在的控制器)
  • pageId (that's the page id where your plugin is implemented) pageId(这是实现插件的页面ID)
  • namespace (that's a name built from your plugin and your extension, in your case tx_myextension_{pluginName} 命名空间(根据您的插件和扩展名构建的名称,在您的情况下为tx_myextension_{pluginName}

Then, you can access the action by 然后,您可以通过以下方式访问操作

http(s)://your.domain.tld/index.php?id={pageId}&{namespace}[controller]={controllerName}&{namespace}[action]={actionName}

I assume you're using the same extension for calling the external plugin. 我假设您使用相同的扩展名来调用外部插件。 You can use fluid viewhelper to create URL for calling controller action. 您可以使用fluid viewhelper创建用于调用控制器操作的URL。

1) If you want to use URL for calling action use below Uri / ActionViewHelper . 1)如果要使用URL调用操作,请在Uri / ActionViewHelper下使用

<f:uri.action action="NULL" arguments="{foo: 'bar'}" controller="NULL" extensionName="NULL" pluginName="NULL" pageUid="123" pageType="123" noCache="1" noCacheHash="1" section="''" format="''" linkAccessRestrictedPages="1" additionalParams="{foo: 'bar'}" absolute="1" addQueryString="1" argumentsToBeExcludedFromQueryString="{foo: 'bar'}" addQueryStringMethod="NULL">
</f:uri.action>

You can use In-line notation. 您可以使用嵌入式符号。

    {f:uri.action(action: 'NULL', arguments: {foo: 'bar'}, controller: 'NULL', extensionName: 'NULL', pluginName: 'NULL', pageUid: 123, pageType: 123, noCache: 1, noCacheHash: 1, section: '''', format: '''', linkAccessRestrictedPages: 1, additionalParams: {foo: 'bar'}, absolute: 1, addQueryString: 1, argumentsToBeExcludedFromQueryString: {foo: 'bar'}, addQueryStringMethod: 'NULL')}

2) Using Form : If you're submitting the form, you have a configuration for the form to calling the action. 2) 使用表单 :如果您要提交表单,则具有用于调用操作的表单配置。

<f:form additionalAttributes="{foo: 'bar'}" data="{foo: 'bar'}" action="NULL" arguments="{foo: 'bar'}" controller="NULL" extensionName="NULL" pluginName="NULL" pageUid="123" object="[mixed]" pageType="123" noCache="1" noCacheHash="1" section="''" format="''" additionalParams="{foo: 'bar'}" absolute="1" addQueryString="1" argumentsToBeExcludedFromQueryString="{foo: 'bar'}" fieldNamePrefix="NULL" actionUri="NULL" objectName="NULL" hiddenFieldClassName="NULL" enctype="NULL" method="NULL" name="NULL" onreset="NULL" onsubmit="NULL" class="NULL" dir="NULL" id="NULL" lang="NULL" style="NULL" title="NULL" accesskey="NULL" tabindex="123" onclick="NULL">
</f:form>

Hope this help you! 希望这对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM