【问题标题】:Typo3 Extbase: get domain in CommandControllerTypo3 Extbase:在 CommandController 中获取域
【发布时间】:2014-03-10 14:37:16
【问题描述】:

我正在尝试在这样的命令操作中访问我网站的基本网址:

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" );
    }

}

当我从调度程序后端模块运行命令时,域看起来没问题,但是当它自动运行时,结果是:

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

在这种情况下获取域的正确方法是什么?

【问题讨论】:

    标签: dns controller command typo3 extbase


    【解决方案1】:

    PHP 通过服务器调用知道域。如果您的站点位于特定服务器上,则您可能有多个指向该服务器的 url。您的 PHP 本身并不知道他拥有哪个域。只有从用户正在执行 PHP 的请求中,才能在 Typo3/Extbase 可以读取的 $_SERVER-var 中获取此信息。如果您想获取 url,我假设您的脚本在不同的服务器上运行?能不能把每台服务器不同的配置放到服务器上?

    执行此操作的一种方法是存储来自用户调用的 url 并在您的 Background-Module 中读取。

    【讨论】:

    • 谢谢克里斯蒂安,您建议的方法是我使用的方法。我将 url 作为参数传递给计划任务操作。
    【解决方案2】:

    说清楚:如果您自动运行调度程序并因此在 CLI 模式下触发 PHP,则没有请求 URL / 它是空的,就像名称已经暗示您在命令行界面模式下运行一样。

    Typoscript 具有可设置和可切换的 baseURL,但即使在那里调用的域也未定义,这是完全正确的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-16
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 2012-05-28
      • 1970-01-01
      相关资源
      最近更新 更多