Template.php 902 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Abstract controller class for automatic templating.
  4. *
  5. * @package KO7
  6. * @category Controller
  7. *
  8. * @copyright (c) 2007-2016 Kohana Team
  9. * @copyright (c) since 2016 Koseven Team
  10. * @license https://koseven.dev/LICENSE
  11. */
  12. abstract class KO7_Controller_Template extends Controller {
  13. /**
  14. * @var View page template
  15. */
  16. public $template = 'template';
  17. /**
  18. * @var boolean auto render template
  19. **/
  20. public $auto_render = TRUE;
  21. /**
  22. * Loads the template [View] object.
  23. */
  24. public function before()
  25. {
  26. parent::before();
  27. if ($this->auto_render === TRUE)
  28. {
  29. // Load the template
  30. $this->template = View::factory($this->template);
  31. }
  32. }
  33. /**
  34. * Assigns the template [View] as the request response.
  35. */
  36. public function after()
  37. {
  38. if ($this->auto_render === TRUE)
  39. {
  40. $this->response->body($this->template->render());
  41. }
  42. parent::after();
  43. }
  44. }