Mixin_MVC_Controller_Instance_Methods

Adds methods for MVC Controller.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/mvc/package.module.mvc.php  
  1. class Mixin_MVC_Controller_Instance_Methods extends Mixin 
  2. function set_content_type($type) 
  3. switch ($type) { 
  4. case 'html': 
  5. case 'xhtml': 
  6. $type = 'text/html'; 
  7. break; 
  8. case 'xml': 
  9. $type = 'text/xml'; 
  10. break; 
  11. case 'rss': 
  12. case 'rss2': 
  13. $type = 'application/rss+xml'; 
  14. break; 
  15. case 'css': 
  16. $type = 'text/css'; 
  17. break; 
  18. case 'javascript': 
  19. case 'jscript': 
  20. case 'emcascript': 
  21. $type = 'text/javascript'; 
  22. break; 
  23. case 'json': 
  24. $type = 'application/json'; 
  25. break; 
  26. case 'jpeg': 
  27. case 'jpg': 
  28. case 'jpe': 
  29. $type = 'image/jpeg'; 
  30. break; 
  31. case 'gif': 
  32. $type = 'image/gif'; 
  33. break; 
  34. case 'png': 
  35. $type = 'image/x-png'; 
  36. break; 
  37. case 'tiff': 
  38. case 'tif': 
  39. $type = 'image/tiff'; 
  40. break; 
  41. case 'pdf': 
  42. $type = 'application/pdf'; 
  43. break; 
  44. $this->object->_content_type = $type; 
  45. return $type; 
  46. function do_not_cache() 
  47. if (!headers_sent()) { 
  48. header('Cache-Control: no-cache'); 
  49. header('Pragma: no-cache'); 
  50. function expires($time) 
  51. $time = strtotime($time); 
  52. if (!headers_sent()) { 
  53. header('Expires: ' . strftime("%a, %d %b %Y %H:%M:%S %Z", $time)); 
  54. function http_error($message, $code = 501) 
  55. $this->message = $message; 
  56. $method = "http_{$code}_action"; 
  57. $this->{$method}(); 
  58. function is_valid_request($method) 
  59. return TRUE; 
  60. function is_post_request() 
  61. return "POST" == $this->object->get_router()->get_request_method(); 
  62. function is_get_request() 
  63. return "GET" == $this->object->get_router()->get_request_method(); 
  64. function is_delete_request() 
  65. return "DELETE" == $this->object->get_router()->get_request_method(); 
  66. function is_put_request() 
  67. return "PUT" == $this->object->get_router()->get_request_method(); 
  68. function is_custom_request($type) 
  69. return strtolower($type) == strtolower($this->object->get_router()->get_request_method()); 
  70. function get_router() 
  71. return C_Router::get_instance(); 
  72. function get_routed_app() 
  73. return $this->object->get_router()->get_routed_app(); 
  74. /** 
  75. * Returns the value of a parameters 
  76. * @param string $key 
  77. * @return mixed 
  78. */ 
  79. function param($key, $prefix = NULL, $default = NULL) 
  80. return $this->object->get_routed_app()->get_parameter($key, $prefix, $default); 
  81. function set_param($key, $value, $id = NULL, $use_prefix = FALSE) 
  82. return $this->object->get_routed_app()->set_parameter($key, $value, $id, $use_prefix); 
  83. function set_param_for($url, $key, $value, $id = NULL, $use_prefix = FALSE) 
  84. return $this->object->get_routed_app()->set_parameter($key, $value, $id, $use_prefix, $url); 
  85. function remove_param($key, $id = NULL) 
  86. return $this->object->get_routed_app()->remove_parameter($key, $id); 
  87. function remove_param_for($url, $key, $id = NULL) 
  88. $app = $this->object->get_routed_app(); 
  89. $retval = $app->remove_parameter($key, $id, $url); 
  90. return $retval; 
  91. /** 
  92. * Gets the routed url, generated by the Routing App 
  93. * @return string 
  94. */ 
  95. function get_routed_url($with_qs = FALSE) 
  96. return $this->object->get_routed_app()->get_app_url(FALSE, $with_qs); 
  97. /** 
  98. * Gets the absolute path of a static resource 
  99. * @param string $path 
  100. * @param string $module 
  101. * @param boolean $relative 
  102. * @return string 
  103. */ 
  104. function get_static_abspath($path, $module = FALSE, $relative = FALSE) 
  105. return C_Fs::get_instance()->find_static_abspath($path, $module); 
  106. /** 
  107. * Gets the relative path of a static resource 
  108. * @param string $path 
  109. * @param string $module 
  110. * @return string 
  111. */ 
  112. function get_static_relpath($path, $module = FALSE) 
  113. return C_Fs::get_instance()->find_static_abspath($path, $module, TRUE); 
  114. function get_static_url($path, $module = FALSE) 
  115. return C_Router::get_instance()->get_static_url($path, $module); 
  116. /** 
  117. * Renders a template and outputs the response headers 
  118. * @param string $name 
  119. * @param array $vars 
  120. */ 
  121. function render_view($name, $vars = array(), $return = FALSE) 
  122. $this->object->render(); 
  123. return $this->object->render_partial($name, $vars, $return); 
  124. /** 
  125. * Outputs the response headers 
  126. */ 
  127. function render() 
  128. if (!headers_sent()) { 
  129. header('Content-Type: ' . $this->object->_content_type . '; charset=' . get_option('blog_charset'), true); 
  130. /** 
  131. * Renders a view 
  132. */ 
  133. function render_partial($template, $params = array(), $return = FALSE, $context = NULL) 
  134. // We'll use the name of the view as the context if one hasn't been provided 
  135. if (is_null($context)) { 
  136. $context = $template; 
  137. $view = $this->object->create_view($template, $params, $context); 
  138. return $view->render($return); 
  139. function create_view($template, $params = array(), $context = NULL) 
  140. $factory = C_Component_Factory::get_instance(); 
  141. $view = $factory->create('mvc_view', $template, $params, NULL, $context); 
  142. return $view;