Sitemap.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace sitemap;
  3. function print_a( $a ){
  4. echo "<pre>";
  5. print_r( $a );
  6. echo "</pre>";
  7. }
  8. use yii\base\BootstrapInterface;
  9. use yii;
  10. use yii\base\Module;
  11. class Sitemap extends Module implements BootstrapInterface
  12. {
  13. public $layout = "@sitemap/views/main.php";
  14. // public $defaultRoute = 'default';
  15. public function init()
  16. {
  17. parent::init();
  18. // $this->bootstrap();
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function bootstrap($app)
  24. {
  25. // parent::bootstrap($app);
  26. $prefix = '/';
  27. if ($urlManager = $app->getUrlManager() && 0) {
  28. $urlManager->addRules([
  29. // $prefix . '<module:' . $this->id . '>/<controller:\w+>/<action:\w+>/<page:\d+>' => '<module>/<controller>/<action>',
  30. $prefix . '<module:' . $this->id . '>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
  31. $prefix . '<module:' . $this->id . '>/<controller:\w+>' => '<module>/<controller>/index',
  32. ], true);
  33. }
  34. $app->getUrlManager()->addRules([
  35. [
  36. 'pattern' => 'sitemap/sitemap',
  37. 'route' => '/sitemap/default/index',
  38. 'suffix' => '.xml'
  39. ],
  40. 'sitemap/sitemap.xml' => 'sitemap/default/index',
  41. 'sitemap/news/<page:\d+>' => 'sitemap/default/news'
  42. ], true);
  43. }
  44. }