PDA

View Full Version : Mapping hashed URLs to views



aaronwbg
24 Nov 2010, 5:21 PM
I'm excited to create a mobile Wordpress theme using Sencha Touch. So far (using some hardcoded test model/data) I have a list panel view to show an index of posts, and a detail panel view to show the full post text.

What I need to do is come up with a way to have unique urls for each state/view. So for example the site root would load the list panel view. I can grasp that part. But I need individual posts to load their detail views. So something like http://myWPblog.com/123/this-is-a-single-post-url should show me that detail panel view.

I get the sense that the solution has to do with hashed urls, but I can't seem to find any examples of Sencha Touch mobile sites with this kind of URL structure. Any help to get me started learning how to do this will be met with sincere gratitude! Thanks.

Steffen Hiller
24 Nov 2010, 7:14 PM
Check the twitter example, it uses routes and the history stuff. Also check the docs of Ext.Application for info on the routes and history functionality.

aaronwbg
24 Nov 2010, 7:15 PM
Great, thanks for the reply and I'll take a look at those resources.

aaronwbg
26 Nov 2010, 4:00 PM
As I understand it, the url structure of the history functionality follows the pattern:
http://example.org/#controller/action

But if I have an incoming link of example.org/348/some-blog-post, I'm not sure where to begin to translate that to a post detail view of, say, example.org/#viewpost/348.

herkulano
26 Nov 2010, 4:09 PM
in routes.js you set the variables/options you want to pass in the URL "viewpost/:postid" then in the controler you do a function/action that gets the variables/options as parameters and maybe passes them to the next view or whatever you want, e.g.:
viewpost: function (options) {
var postid = options.postid;
// do something with it...
}

hope it helps.

aaronwbg
26 Nov 2010, 4:13 PM
Thanks, it gives me a place to focus. I'm vaguely familiar with the MVC pattern, so it will take some learning.

So I'm assuming I have to structure the app like the Twitter example (Ext.regApplication, etc) and not like the simpler examples using Ext.setup?

herkulano
27 Nov 2010, 2:44 AM
Yes, to use the hash URLs you need to implement the regApp, like in the Twitter or Kiva example.