Hej, zrobiłem podział sitemapy, lecz mam problem z powtarzalnym kodem i chciałbym uniknąć tworzenia dodatkowych funkcji, żeby tylko zmienić wartość offsetu przy robieniu query (pobieram artykuły po 2000).
public function index() {
$this->layout = false;
$sitemaps = [
['loc' => (APP . '\Config\Config')::getUrl() . '/sitemaps/articles0/sitemap.xml'],
['loc' => (APP . '\Config\Config')::getUrl() . '/sitemaps/articles1/sitemap.xml']
];
$this->set('sitemaps', $sitemaps);
}
public function articles0() {
$this->loadModel('Article');
$articles = $this->Article->query(
'SELECT url, modified FROM articles WHERE site_id='
. $this->siteId . " AND status='publish' AND (redirect_url is null OR redirect_url = '') AND landing_page_id is null AND calc_id = '0' LIMIT 2000"
);
foreach ($articles as $article) {
$urls[] = [
'loc' => (APPNAME . '\Config\Config')::getUrl() . '/-' . $article['url'],
'lastmod' => date('Y-m-d\TH:i:s+00:00', strtotime($article['modified'])) ];
}
$this->set('urlset', $urls);
$this->render('sitemaps/urlset', false);
}
public function articles1() {
$this->loadModel('Article');
$articles = $this->Article->query(
'SELECT url, modified FROM articles WHERE site_id='
. $this->siteId . " AND status='publish' AND (redirect_url is null OR redirect_url = '') AND landing_page_id is null AND calc_id = '0' LIMIT 2000, 2000"
);
foreach ($articles as $article) {
$urls[] = [
'loc' => (APPNAME . '\Config\Config')::getUrl() . '/-' . $article['url'],
'lastmod' => date('Y-m-d\TH:i:s+00:00', strtotime($article['modified'])) ];
}
$this->set('urlset', $urls);
$this->render('sitemaps/urlset', false);
}
Chciałbym mieć tylko jedną funkcje articles(), tylko pojawia się problem, że muszę podać nazwę funkcji i nie wiem jak je dynamicznie generować. Pozdrawiam