PDA

View Full Version : Passing MVC controller and action in query string parameters



basememara
7 Dec 2011, 10:43 AM
Instead of creating multiple html pages such as index.html, product.html, etc, I want to have one index.html and pass the controller and actions into the URL like this:

http://mydomain.com/?controller=product&action=list

..or maybe like this:

http://mydomain.com/?route=product/list

Is there a way to do this or am I supposed to be approaching this differently for Touch 2?

rdougan
7 Dec 2011, 11:24 AM
Routes will be part of the MVC package in ST2, they just aren't in PR2. They will do exactly what you are looking for.

basememara
7 Dec 2011, 12:55 PM
Really hoping for that :-? As a workaround, I put some routing logic in my viewport after adding 'autoCreateViewport: true' in my 'Ext.application':


Ext.define('MyApp.view.Viewport', { extend: 'Ext.Panel',


config: {
fullscreen: true,
layout: 'fit'
},


initialize: function() {
//RETRIEVE QUERY PARAMETERS TO HANDLE REQUEST
var reqParams = Ext.Object.fromQueryString(location.search);


//ROUTE PER REQUEST
var reqRoute = (reqParams['route'] || 'product/list').split('/');
var reqController = reqRoute[0].toLowerCase();
var reqAction = reqRoute.length > 1 ? reqRoute[1].toLowerCase() : 'index';
switch (reqController) {
case 'product':
switch (reqAction) {
case 'list':
this.add({ xtype: 'productlist' });
break;
case 'detail':
this.add({ xtype: 'productdetail' });
break;
default:
this.add({ xtype: 'productlist' });
}
break;
default:
this.add({ xtype: 'productlist' });
}


this.callParent();
}
});

It is an ugly hack, but conditionally adding items to the page based on the route parameters.