简体   繁体   English

Typo3 Extbase:在CommandController中获取域

[英]Typo3 Extbase: get domain in CommandController

I'm trying to access the base url of my site inside a command action like this: 我正在尝试通过以下命令操作访问网站的基本URL:

namespace Vendor\TxTest\Command;

class TestCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController
{
    /**
     * logger 
     * 
     * @var \TYPO3\CMS\Core\Log\LogManager
     */
    protected $logger;

    /**
     * Class constructor
     */
    public function __construct()
    {
        $this->logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 'TYPO3\\CMS\\Core\\Log\\LogManager' )->getLogger( __CLASS__ );
    }

    /**
     * Test command
     */
    public function testCommand()
    {
        $homeUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl( '/' );

        $this->logger->info( 'url: ' . $homeUrl );

        $this->logger->info( "\n\r\n\r" );
    }

}

When I run the command from the Scheduler backend module, the domain looks ok, but when it runs automatically, the result is: 当我从Scheduler后端模块运行命令时,域看起来正常,但是当它自动运行时,结果是:

Mon, 10 Mar 2014 ... component="Vendor.TxNews.Command.TestCommandController": url: http:///

What is the correct way to get the domain in this context? 在这种情况下获取域的正确方法是什么?

PHP knows the domain from the server-call. PHP通过服务器调用知道域。 If your site is on a specific server, you might have several urls pointing to this server. 如果您的站点在特定服务器上,则可能有多个指向该服务器的URL。 Your PHP does not know by itself which domain he has. 您的PHP本身并不知道他拥有哪个域。 Only from the request that the user is doing PHP is getting this information in the $_SERVER-var that Typo3/Extbase can read. 只有从用户正在使用PHP的请求中,此信息才能在Typo3 / Extbase可以读取的$ _SERVER-var中获得。 I assume your script is running on different servers if you want to get the url? 如果您要获取网址,我假设您的脚本在不同的服务器上运行? Can you put a configuration on the server that is different for each server? 您可以在服务器上放置每个服务器不同的配置吗?

One approach to do this would be to store the url from a user-call and read this in your Background-Module. 一种实现方法是将用户调用中的网址存储在您的Background-Module中。

to put it clear: If you run the scheduler automatically and therefore trigger PHP in CLI mode, there is no request URL / it is empty, as like the name already suggests u run in command line interface mode. 明确地说:如果您自动运行调度程序并因此在CLI模式下触发PHP,则没有请求URL /它是空的,就像名称已经暗示您在命令行界面模式下运行一样。

Typoscript has the baseURL settable and switchable, but even there the domain of the call is undefined, which is perfectly right. 打字稿具有可设置和可切换的baseURL,但是即使在此调用的域也未定义,这是完全正确的。

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

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