Pregunta

I'm trying to access the base url of my site inside a command action like this:

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:

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

What is the correct way to get the domain in this context?

¿Fue útil?

Solución

PHP knows the domain from the server-call. If your site is on a specific server, you might have several urls pointing to this server. Your PHP does not know by itself which domain he has. Only from the request that the user is doing PHP is getting this information in the $_SERVER-var that Typo3/Extbase can read. 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.

Otros consejos

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.

Typoscript has the baseURL settable and switchable, but even there the domain of the call is undefined, which is perfectly right.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top