MyController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. App::uses('Controller', 'Controller');
  3. /**
  4. * DRY Controller stuff
  5. */
  6. class MyController extends Controller {
  7. /**
  8. * @var array
  9. * @link https://github.com/cakephp/cakephp/pull/857
  10. */
  11. public $paginate = [];
  12. /**
  13. * Fix for asset compress to not run into fatal error loops
  14. */
  15. public function __construct($request = null, $response = null) {
  16. parent::__construct($request, $response);
  17. if ($this->request !== null && (strpos($this->request->here, '/js/cjs/') === 0 || strpos($this->request->here, '/css/ccss/') === 0)) {
  18. unset($this->request->params['ext']);
  19. }
  20. }
  21. /**
  22. * Add headers for IE8 etc to fix caching issues in those stupid browsers
  23. *
  24. * @overwrite to fix IE cacheing issues
  25. * @return void
  26. */
  27. public function disableCache() {
  28. $this->response->header([
  29. 'Pragma' => 'no-cache',
  30. ]);
  31. return parent::disableCache();
  32. }
  33. /**
  34. * Handles automatic pagination of model records.
  35. *
  36. * @overwrite to support defaults like limit, querystring settings
  37. * @param Model|string $object Model to paginate (e.g: model instance, or 'Model', or 'Model.InnerModel')
  38. * @param string|array $scope Conditions to use while paginating
  39. * @param array $whitelist List of allowed options for paging
  40. * @return array Model query results
  41. */
  42. public function paginate($object = null, $scope = [], $whitelist = []) {
  43. if ($defaultSettings = (array)Configure::read('Paginator')) {
  44. $this->paginate += $defaultSettings;
  45. }
  46. return parent::paginate($object, $scope, $whitelist);
  47. }
  48. /**
  49. * Hook to monitor headers being sent.
  50. *
  51. * @return void
  52. */
  53. public function afterFilter() {
  54. parent::afterFilter();
  55. if (Configure::read('App.monitorHeaders') && $this->name !== 'CakeError') {
  56. if (headers_sent($filename, $linenum)) {
  57. $message = sprintf('Headers already sent in %s on line %s', $filename, $linenum);
  58. if (Configure::read('debug')) {
  59. throw new CakeException($message);
  60. }
  61. trigger_error($message);
  62. }
  63. }
  64. }
  65. }