MyController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. App::uses('Controller', 'Controller');
  3. /**
  4. * DRY Controller stuff
  5. * 2011-02-01 ms
  6. */
  7. class MyController extends Controller {
  8. /**
  9. * Fix for asset compress to not run into fatal error loops
  10. * 2012-12-25 ms
  11. */
  12. public function __construct($request = null, $response = null) {
  13. parent::__construct($request, $response);
  14. if (strpos($this->here, '/js/cjs/') === 0 || strpos($this->here, '/css/ccss/') === 0) {
  15. unset($this->request->params['ext']);
  16. }
  17. }
  18. /**
  19. * Add headers for IE8 etc to fix caching issues in those stupid browsers
  20. * 2012-12-25 ms
  21. */
  22. public function disableCache() {
  23. $this->response->header(array(
  24. 'Pragma' => 'no-cache',
  25. ));
  26. return parent::disableCache();
  27. }
  28. /**
  29. * Fix encoding issues on Apache with mod_rewrite
  30. * Uses Configure::read('App.additionalEncoding') to additionally escape
  31. *
  32. * Tip: Set it to `1` for normal mod_rewrite websites routing directly into webroot
  33. * If you use another setup (like localhost/app/webroot) where you use multiple htaccess files or rewrite
  34. * rules you need to raise it accordingly.
  35. *
  36. * 2013-03-02 ms
  37. */
  38. public function redirect($url, $status = null, $exit = true) {
  39. $run = Configure::read('App.additionalEncoding');
  40. if ($run) {
  41. foreach ($url as $key => $value) {
  42. if ($key === '?') {
  43. continue;
  44. }
  45. $value = $this->_encodeUrlPiece($value, $run);
  46. $url[$key] = $value;
  47. }
  48. }
  49. return parent::redirect($url, $status, $exit);
  50. }
  51. public function _encodeUrlPiece($value, $run) {
  52. if (!is_array($value)) {
  53. for ($i = 0; $i < $run; $i++) {
  54. $value = urlencode($value);
  55. }
  56. return $value;
  57. }
  58. return $this->_encodeUrlPiece($value, $run);
  59. }
  60. /**
  61. * Init Packages class if enabled/included
  62. * @deprecated?
  63. * 2012-12-25 ms
  64. */
  65. public function beforeRender() {
  66. if (class_exists('Packages')) {
  67. Packages::initialize($this, __CLASS__);
  68. }
  69. parent::beforeRender();
  70. }
  71. }