model() публичный статический метод

public static model ( null | string $className = __CLASS__ )
$className null | string
Пример #1
0
 /**
  *
  */
 public function actionIndex()
 {
     $module = Yii::app()->getModule('sitemap');
     $sitemapFile = $module->getSiteMapPath();
     if (!file_exists($sitemapFile)) {
         $staticPages = SitemapPage::model()->getData();
         $this->generator->generate($sitemapFile, $staticPages);
     }
     $this->redirect(['/sitemap/sitemap/index'], 301);
 }
Пример #2
0
 public function actionIndex()
 {
     if (!($numberParts = Yii::app()->getCache()->get($this->cacheKeyNumberParts))) {
         if (!Yii::app()->getCache()->get($this->cacheKeyLock)) {
             Yii::app()->getCache()->set($this->cacheKeyLock, true, 90);
             set_time_limit(120);
             $urls = [];
             $cacheTime = $this->getModule()->cacheTime * 3600 + 1;
             $modules = (require_once Yii::getPathOfAlias('sitemap.config') . DIRECTORY_SEPARATOR . 'modules.php');
             foreach ($modules as $name => $moduleModels) {
                 $module = Yii::app()->getModule($name);
                 if (null != $module && $module->getIsInstalled()) {
                     foreach ($moduleModels as $options) {
                         $dataProvider = $options['getDataProvider']();
                         $iterator = new CDataProviderIterator($dataProvider, 100);
                         foreach ($iterator as $model) {
                             $urls[] = $this->getUrlRow($options['getUrl']($model), $options['changeFreq'], $options['priority'], $options['getLastMod']($model));
                         }
                     }
                 }
             }
             $host = Yii::app()->getRequest()->hostInfo;
             $pagesDataProvider = new CActiveDataProvider(SitemapPage::model()->active(), []);
             $pagesIterator = new CDataProviderIterator($pagesDataProvider, 100);
             foreach ($pagesIterator as $page) {
                 $urls[] = $this->getUrlRow($host . '/' . ltrim(str_replace($host, '', $page->url), '/'), $page->changefreq, $page->priority);
             }
             $parts = array_chunk($urls, $this->maxLinksCount);
             foreach ($parts as $key => $part) {
                 $xml = join("", $part);
                 Yii::app()->getCache()->set($this->cacheKeyPart . $key, $xml, $cacheTime);
             }
             $numberParts = count($parts);
             Yii::app()->getCache()->set($this->cacheKeyNumberParts, $numberParts, $cacheTime);
             Yii::app()->getCache()->delete($this->cacheKeyLock);
         }
     }
     header("Content-type: text/xml");
     echo $this->getXmlHead();
     if ($numberParts == 1) {
         echo $this->getUrlSetFromCache(0);
     } else {
         echo $this->getSitemapIndex($numberParts);
     }
     Yii::app()->end();
 }
Пример #3
0
 /**
  * @return array
  */
 public function getData()
 {
     $provider = new CActiveDataProvider(SitemapPage::model()->active());
     $data = [];
     foreach (new CDataProviderIterator($provider) as $page) {
         $data[] = ['location' => $page->url === '/' ? Yii::app()->getBaseUrl(true) : Yii::app()->getBaseUrl(true) . '/' . $page->url, 'changeFrequency' => $page->changefreq, 'priority' => $page->priority, 'lastModified' => null];
     }
     return $data;
 }