Closed w4ugit closed 3 years ago
@w4ugit Looks like you misunderstood a bit the purpose of the variable $outputDir
. The $outputDir
should store the directory where you expect the sitemap to be generated. And the name of the sitemap without any path should be passed to the method setSitemapFileName()
(only sitemap.xml
, not /frontend/web/sitemap.xml
). So for your case, the following code will work:
include 'src/SitemapGenerator.php';
use Icamys\SitemapGenerator\SitemapGenerator;
$yourSiteUrl = 'https://optklin.com.ua';
$outputDir = getcwd() . '/frontend/web/'; // <-------------- the output directory
$generator = new SitemapGenerator($yourSiteUrl, $outputDir);
$generator->toggleGZipFileCreation();
$generator->setMaxURLsPerSitemap(50000);
$generator->setSitemapFileName('sitemap.xml'); // <--------- the sitemap filename
$generator->addURL('/', new DateTime(), 'always', 0.5, []);
$generator->createSitemap();
$generator->writeSitemap();
Also, ensure that you have appropriate permissions for the directory you want to write the sitemap to.
An example of my code
$yourSiteUrl = 'https://optklin.com.ua'; $outputDir = getcwd(); $generator = new \Icamys\SitemapGenerator\SitemapGenerator($yourSiteUrl, $outputDir); $generator->toggleGZipFileCreation(); $generator->setMaxURLsPerSitemap(50000); $generator->setSitemapFileName('/frontend/web/sitemap.xml'); $generator->addURL('/', new \DateTime(), 'always', 0.5, []); $generator->createSitemap(); $generator->writeSitemap();
It only creates such a file
`<?xml version="1.0" encoding="UTF-8"?>
`