简体   繁体   English

如何覆盖 typo3 分机的 controller function?

[英]How can I overwrite a controller function of a typo3 extension?

I have a Typo3 9 application that uses several extensions.我有一个使用多个扩展的 Typo3 9 应用程序。 One of them is the "main" extension and includes various resource files, models, controllers and so on.其中之一是“主要”扩展,包括各种资源文件、模型、控制器等。 Because this extension is developed seperately and I might have to update it later, I don't want to touch its code.因为这个扩展是单独开发的,我以后可能要更新它,所以我不想碰它的代码。 For that reason, I created a separare extension, which already works well to overwrite templates and stylings.出于这个原因,我创建了一个单独的扩展,它已经可以很好地覆盖模板和样式。 However I can't really figure out how to cleanly overwrite controller functions.但是我真的不知道如何干净地覆盖 controller 函数。

Example: The main extension has a controller called "FrontendController.php".示例:主扩展有一个名为“FrontendController.php”的 controller。 This controller has a function called "blogDetailAction", which is called when accessing the detail view of a blog entry.这个 controller 有一个名为“blogDetailAction”的 function,它在访问博客条目的详细视图时被调用。 I want to change/overwrite this function by unsing my extension.我想通过取消扩展名来更改/覆盖此 function。 How would I do that?我该怎么做?

Thank you!谢谢!

If you want to change the code of a class which doesn't provide options like hooks or events , you have to use the XClass (Extending Class) mechanism.如果要更改不提供钩子事件等选项的 class 的代码,则必须使用 XClass(扩展类)机制。

To do that, in your own extension, file EXT:YourExtension/ext_localconf.php, add this kind of code:为此,在您自己的扩展名文件 EXT:YourExtension/ext_localconf.php 中,添加以下代码:

$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][VendorName\ExtensionName\Controller\FrontendController::class] = [
   'className' => YourVendorName\YourExtensionName\Xclass\NewFrontendController::class
];

Then in your NewFrontendController.php:然后在你的 NewFrontendController.php 中:

class NewFrontendController extends \VendorName\ExtensionName\Controller\FrontendController
{
   // Your code here
}

Every class created with \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance() can be extended with XClass mechanism.使用\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance()创建的每个 class 都可以使用 XClass 机制进行扩展。

But you have to know that using XClass is risky because: neither the core, nor extensions authors can guarantee that XCLASSes will not break if the underlying code changes.但是您必须知道使用 XClass 是有风险的,因为:无论是核心作者还是扩展作者都不能保证 XCLASS 不会在底层代码更改时中断。

More information here: https://docs.typo3.org/m/typo3/reference-coreapi/9.5/en-us/ApiOverview/Xclasses/Index.html更多信息在这里: https://docs.typo3.org/m/typo3/reference-coreapi/9.5/en-us/ApiOverview/Xclasses/Index.html

暂无
暂无

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

相关问题 如何在我的 Typo3 分机内发送邮件 - How can i send Mails within my Typo3 extension 扩展自定义 TYPO3 9.5 扩展时出现问题 - 我无法在 controller 中添加操作 - Problem with extending custom TYPO3 9.5 extension - I can't add action in controller TYPO3中无法确定扩展和插件的默认控制器为ERROR - The default controller for extension and plugin can not be determined ERROR in TYPO3 Typo3:如何通过属性验证覆盖默认错误消息? - Typo3: How can I overwrite the default error message by property validation? TYPO3 无法确定扩展的默认controller - TYPO3 The default controller for extension cannot be determined Typo3调度程序:我可以通过它以某种方式执行扩展控制器的动作吗? 或者如何用它运行我自己的代码? - Typo3 scheduler: Can i somehow execute Action of controllers of my extension with it? Or how to run my own code with it? TYPO3:如何创建带有typeNum = 20的自定义页面类型url并在Controller上引用它 - TYPO3: How can i create a custom page type url with typeNum=20 and reference that on the Controller 如何使用 PHP 扩展覆盖内部 Zend 函数? - How can I overwrite an internal Zend function with a PHP extension? Typo3 8.7:Powermail 6.1:无法确定扩展名“ Powermail”和插件“ Pi1”的默认控制器 - Typo3 8.7: Powermail 6.1: the default controller for extension “Powermail” and plugin “Pi1” can not be determined TYPO3 7.6.10:如何扩展felogin扩展? - TYPO3 7.6.10: How to extend the felogin extension?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM