Hybrid View
-
20 Jan 2011 5:45 AM #1
Problem with passing multiple parameters in url with Sencha-touch MVC routing
Problem with passing multiple parameters in url with Sencha-touch MVC routing
Hi,
I stuck in a place where I need to pass several parameters in url while using Ext.Router & built-in MVC in Sencha-touch. Having initialized routing as below:
entering url "localhost/#users/show/3" executes 'show' action in 'users' controller with "3" as passed parameter.Code:Ext.Router.draw(function (map) { map.connect(':controller/:action/:parameter'); }
works just fine, until several parameters need to be passed to an action for example "localhost/#users/search/type=3"e=john", I would expect that 'search' action in 'users' controller would be executed with string parameter as "type=3"e=john", but routing does not call any action if any spacial char is passed as parameter (':', '=',' &').
I assume this is a restricted by routing, but I dont get it why.
Other option is to register routes as following:
but I dont find it the best practice (for example when the number of parameters is dynamic)Code:map.connect(':controller/:action/:parameter1/:parameter2/:parameter3/:parameter4');
Could anyone explain this to me how multiple parameters should be passed to action using routing, assuming that each parameter should be recognizable by its name.
cheers
-
21 Jan 2011 1:20 AM #2
Sorry my friend. I don't have an answer. I really want to know the solution for this problem. Very good question!
-
25 Jan 2011 3:00 PM #3
Does anyone know why I can't find Router in either the EXT JS or Sencha Touch API docs? Very strange.
-
26 Jan 2011 7:04 AM #4
The docs have a few small holes in them. 'Viewport' is another missing class.
-
1 Feb 2011 8:36 PM #5
I can't say what the purpose is, but probably mostly to be simpler and more integrated with the basic 'app' model they have.
You can get the '&foo=bar' part to come through the Router into the controller by changing 'Ext.util.Route::createMatcherRegex' to allow the characters in a trailing (potentially ':rest' ) attribute and use that with a route like:
for 'localhost/#users/search/type=3"e=john' or change the last slash to a '&' and you could use 'localhost/#users/search&type=3"e=john' which might be a bit more standard.Code:map.connect(':controller/:action/:rest');
Code:createMatcherRegex: function(url) { var paramsInMatchString = this.paramsInMatchString, length = paramsInMatchString.length, i, cond, matcher; for (i = 0; i < length; i++) { cond = this.conditions[paramsInMatchString[i]]; if (i == length - 1) { matcher = Ext.util.Format.format("({0})", cond || "[%a-zA-Z0-9\\_\\s,\\&\\=]+"); } else { matcher = Ext.util.Format.format("({0})", cond || "[%a-zA-Z0-9\\_\\s,]+"); } url = url.replace(new RegExp(paramsInMatchString[i]), matcher); } return new RegExp("^" + url + "$"); }
-
3 Feb 2011 8:16 AM #6
Similar Threads
-
Sencha Touch + MVC?
By Bucs in forum Sencha Touch 1.x: DiscussionReplies: 16Last Post: 2 Jul 2011, 12:19 PM -
Using Sencha Touch with ASP .Net MVC
By atulbahl in forum Sencha Touch 1.x: DiscussionReplies: 8Last Post: 24 Mar 2011, 12:33 PM -
Sencha Touch's MVC
By Steffen Hiller in forum Sencha Touch 1.x: DiscussionReplies: 4Last Post: 27 Nov 2010, 8:24 PM -
Sencha Touch MVC
By crysfel in forum Sencha Touch 1.x: DiscussionReplies: 2Last Post: 25 Nov 2010, 12:36 AM -
change store URL or passing parameters
By Brendan in forum Ext 2.x: Help & DiscussionReplies: 4Last Post: 28 Jan 2009, 6:04 PM


Reply With Quote