Cms.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace Entity;
  3. class Cms extends ModelBase
  4. {
  5. protected function install()
  6. {
  7. $dbPrefix = $this->getDbPrefix();
  8. $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}cms` (
  9. `id` INTEGER(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  10. `shurl` VARCHAR(255) NOT NULL,
  11. `controller` VARCHAR(255) NOT NULL,
  12. `order` INTEGER UNSIGNED NOT NULL DEFAULT 0,
  13. UNIQUE(`shurl`)
  14. )");
  15. if ($result === false)
  16. throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
  17. self::createRoute("/", "\\Controller\\HomeController", 50);
  18. self::createRoute("/:category", "\\Controller\\CategoryController", 50);
  19. self::createRoute("/:category/:product", "\\Controller\\ProductController", 50);
  20. self::createRoute("/:product", "\\Controller\\ProductController", 60);
  21. return true;
  22. }
  23. private function createRoute($category, $controller, $order)
  24. {
  25. $cms = new self();
  26. $cms->shurl = $category;
  27. $cms->controller = $controller;
  28. $cms->order = $order;
  29. $cms->save();
  30. }
  31. }