template.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Part of the Fuel framework.
  4. *
  5. * @package Fuel
  6. * @version 1.5
  7. * @author Fuel Development Team
  8. * @license MIT License
  9. * @copyright 2010 - 2013 Fuel Development Team
  10. * @link http://fuelphp.com
  11. */
  12. namespace Fuel\Core;
  13. /**
  14. * Template Controller class
  15. *
  16. * A base controller for easily creating templated output.
  17. *
  18. * @package Fuel
  19. * @category Core
  20. * @author Fuel Development Team
  21. */
  22. abstract class Controller_Template extends \Controller
  23. {
  24. /**
  25. * @var string page template
  26. */
  27. public $template = 'template';
  28. /**
  29. * Load the template and create the $this->template object
  30. */
  31. public function before()
  32. {
  33. if ( ! empty($this->template) and is_string($this->template))
  34. {
  35. // Load the template
  36. $this->template = \View::forge($this->template);
  37. }
  38. return parent::before();
  39. }
  40. /**
  41. * After controller method has run output the template
  42. *
  43. * @param Response $response
  44. */
  45. public function after($response)
  46. {
  47. // If nothing was returned default to the template
  48. if (empty($response))
  49. {
  50. $response = $this->template;
  51. }
  52. return parent::after($response);
  53. }
  54. }