Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added request and router methods to BaseController - no more hardcode…

…d attributes.
  • Loading branch information...
commit a6d0682f12cb9508f64c8450172c77174cb99b5c 1 parent 5ab381e
@fk1blow authored
Showing with 30 additions and 10 deletions.
  1. +30 −10 lib/Controller/BaseController.js
View
40 lib/Controller/BaseController.js
@@ -3,17 +3,13 @@ var ActiveRouter = require('../Router/ActiveRouter'),
Request = require('../Http/Request');
+function toUpcase(string) {
+ return string.substr(0, 1).toUpperCase() + string.substr(1);
+}
+
+
var BaseController = Klass({
- attributes: {
- controller_name: function() { return ActiveRouter.getControllerName() },
-
- action_name: function() { return ActiveRouter.getActionName() },
-
- /**
- * I can't tell if it's safe to expose all the Request object
- */
- request: function() { return Request.Factory() }
- },
+ attributes: {},
methods: {
render: function(view, options) {
@@ -22,6 +18,30 @@ var BaseController = Klass({
renderToResponse: function(string_output, content_type) {
View.renderToResponse(string_output, content_type);
+ },
+
+ request: function(field) {
+ if(field && field.length > 0) {
+ var f_method = 'get' + toUpcase(field);
+ try {
+ return Request.Factory()[f_method]();
+ } catch(e) {
+ throw new Error('Unable to call ' + f_method);
+ }
+ }
+ return null;
+ },
+
+ router: function(field) {
+ if(field && field.length > 0) {
+ var f_method = 'get' + toUpcase(field);
+ try {
+ return ActiveRouter[f_method]();
+ } catch(e) {
+ throw new Error('Unable to call ' + f_method);
+ }
+ }
+ return null;
}
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.