I would like to format my URL like so:
/teacher/page:2
to
/teacher
I would like to achieve this result by using as less code as possible (perhaps only from routes.php?), without modifying how the PaginatorHelper behaves.
Thank you for your help!
You can accomplish this with:
ajax
form posts instead of gets (requires altering the pagination
helper)
But I would advise against it. This is designed for good usability. If you change it, It will make your site less user friendly than you may want it to be. I know I would be frustrated trying to jump to a specific page only to find out I have to click my way to page 35. Yuck!
Related
So I have been plowing the internet to understand or see and example of what I want to do.
It shouldn't be difficult, but something is just missing to me.
The Scenario
I have a search page, built from 2 directives/ ui-views like this:
What I want to achieve
When I press Search, I want to trigger the Search Results directive/ view to fetch the corresponding results based on the search form parameter.
Where I am stuck
Because I have 2 separate directives, I can make them share information using the parent controller, OR the search service I have (to communicate with the backend).
However, The search directive can write information to either one, BUT the results are still not triggered. Unless I actively check for changes every once in a while for changes, I won't get the cling saying I have been triggered.
That is definitely not the the AngularJS way, and I just don't seem to have enough experience to think of something else.
What I am asking you
How would you approach this situation, what will you use to make this page as clean as you can, and modular (of course).
I've had ideas that at the worst case scenario, I will omit the modular approach, and just do it dirty, but working.
Still, this annoys me because as far as I know, this is one of the STRONGEST features of Angular.
I'd appreciate if you could attach some code for all to see and learn
As far as I see, this page is turning around of search functionality. So what I suggest you to implement here - to include search text into your routing parameters.
Your Search box which is help user to write down search query. Make it add search query to routing as some parameter, once user click Search button. It will be the only one responsibility of Search box, to change location URL, literally.
Action: User wrote down Founder in the search box input and pressed button Search.
Result: Location changed from #/search/ to #/search/Founder
The search result view should just respond to the location change. If the search string is changed, it should do all needed calls to the server, and return, process and represent search result in the Search result block.
At the moment in my Angular app, I'm using URLs with the ID e.g.
mysite.com/story/34jkh4432jkdasddasdsadasdas3
For what reasons would it be beneficial if any to instead do something like:
mysite.com/story/34jkh4432jkdasddasdsadasdas3/the-story-title
Is it strongly recommended? (e.g. for helping SEO) (An obvious advantage i see is if the URL is shared, easier for people to know roughly what they are about to see).
Else wouldn't the URL just become really long?
Also to implement it - I presume I can technically ignore the 'slug title' as its just that long ID i use? It would just be there for SEO/user readability.
Is that the correct way to think of it?
I notice even on this page, if I remove anything after the post ID it still takes me to the correct page.
Thanks.
I'm working on a project that requires that most UI state is reproducible via URL. In a traditional (server-side) app, I could use both URL parameters like:
/resources/:id
and unordered optional query string parameters, like:
/resources/:id?page=5&sort=date
Is there an idiomatic way to achieve this with Backbone/Marionette routing? I don't want to have to configure routes for every possible combination of parameters.
The fact that I don't see this addressed much makes me think I may be barking up the wrong tree, approach-wise, but I do think being able to represent as much UI state as possible in the URL is pretty important to a lot of projects.
It looks like the best option is the now-orphaned backbone-query-parameters project.
It supports routes exactly in the form I'm looking for:
#resources/:id?flag=true
URL parameters are not really enforced by Backbone/Marionette. One possible reason is that URL parameters are not SEO friendly.
Instead, you can configure optional URL fragments which will work pretty much like URL parameters, this way:
/resources/:id(/page/:page)(/sort/:sort)
If you do this way, the only gotcha here is that this sequence of "parameters" need to be ordered.
HOWEVER if you need it to be unordered, you can simply use Regular Expressions with router.route() method inside your initialize, as explained in Router#route
I have a ComboBox and I'd like to fetch data from server first when user type at least 3 characters.
I've used dojo.data.* but it's deprecated and I cannot find something similar in dojo.store.* and xhr|ajax in one sentence. Do you have some tips?
I use declarative markup.
You probably used the dojox/data/QueryReadStore? There is no similar store at the moment I think. The best alternative you have (with the dojo/store API) is the JsonRest store.
But it isn't exactly the same, so you might have to extend it. You should probably start by looking at both API's (the old and the new API) and compare the dojox/data/QueryReadStore and the dojo/store/JsonRest to successfully extend it.
I'm trying to wrap my head around backbone.js but I'm finding it hard due to the lack of (IMO) good examples.
First of all, what is the best way of getting a link to an object.
If I want to get the edit url of an Album model I could do album.url() + '/edit', is this really the best way?
Also, I'm trying to make my application work 100% without javascript so I don't want my URLs/links to say /albums/#1/edit, I want it to be /albums/1/edit and override this in JS.
I'm thinking I create normal URLs and use jQuery.live to call router.navigate in backbone.js
I never got this to work however, when I call router.navigate('/albums/2', true) the URL changes but my show action is never called. If I refresh it's called so the route is matched.
What am I missing?
The basic answer, which is kind of frustrating, is "there is no preferred way!". Backbone.js doesn't tell you how to set up links, you can do it any way you like. I found this flexibility just as annoying as you do, at least at first.
So here's the way I'm approaching this on my current project, with the (big) caveat that this is just one of many ways to do things in Backbone:
For the most part, I don't use actual links. There's no explicit reason not to, but it means you have to keep track of a bunch of URL strings that have to be consistent. I would rather stick all the URL formatting in my routers and not deal with it elsewhere.
To open a new "top-level" view, like an editing screen, I set something that fires an event. In the application I'm currently working on, I have a global State model, and to open a new view I call state.set({ topview: MyTopView }). This causes the state object to trigger change:topview.
Any piece of the UI that needs to change when the top-level view changes has an update method bound to change:topview. When the event fires, they look at state.get('topview') and update as necessary.
I treat my routers as only marginally specialized parts of the UI - they're essentially views that render in the browser address bar, rather than the window. Like other views, they update the state object on UI events (i.e. a new URL), and like other views, they listen to the state object for changes that cause them to update. The logic that the editing screen has the URL albums/<albumid>/edit is fully encapsulated in the router, and I don't refer to it anywhere else.
This works well for me, but it adds an entirely new pattern, the global State object, to the Backbone structure, so I can hardly call this the "preferred" approach.
Update: Also note that .url(), in the Backbone idiom, refers to the model's URL in the back-end API, not the front-end URL (it's not like Django's get_absolute_url). There is no method in the default Backbone setup that gives you a user-facing URL for your model - you'd have to write this yourself.
Also, I'm trying to make my application work 100% without javascript; so I don't want my URLs/links to say /albums/#1/edit, I want it to be /albums/1/edit and override this in JS.
you can do exactly this w/ pushState. just enable it in your Backbone.history.start call:
Backbone.history.start({pushState: true})
this tells Backbone to use the HTML5 History API (a.k.a. "PushState"), which uses full URLs exactly like you're wanting.
read up on the history api here: http://diveintohtml5.ep.io/history.html
and I wrote up a 2 part series on using pushstate w/ the second part focusing on progressive enhancement in backbone, to do what you're needing:
http://lostechies.com/derickbailey/2011/09/26/seo-and-accessibility-with-html5-pushstate-part-1-introducing-pushstate/
and
http://lostechies.com/derickbailey/2011/09/26/seo-and-accessibility-with-html5-pushstate-part-2-progressive-enhancement-with-backbone-js/
hope that helps :)