CategoryPresenter.php 980 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Presenters;
  3. use App\Models\Category;
  4. /**
  5. * Class CategoryPresenter
  6. *
  7. * @package namespace App\Presenters;
  8. */
  9. class CategoryPresenter
  10. {
  11. /**
  12. * category selects
  13. *
  14. * @param int $defaultCategoryId
  15. * @param string $nullText
  16. * @return string
  17. */
  18. public function getSelect($defaultCategoryId = 0, $nullText = '请选择', $nullValue = 0)
  19. {
  20. $category = Category::getNestedList('name', null, '&nbsp;&nbsp;&nbsp;&nbsp;');
  21. $select = "<select id='cate_id' name='cate_id' class='form-control'>";
  22. $select .= "<option value='".$nullValue."'>--".$nullText."--</option>";
  23. if ($category) {
  24. foreach ($category as $key => $value) {
  25. $selected = $key == $defaultCategoryId ? " selected " : "";
  26. $select .= "<option value='".$key."' ".$selected.">".$value."</option>";
  27. }
  28. }
  29. $select .= "</select>";
  30. return $select;
  31. }
  32. }