1

PLEASE INVEST SOME TIME READING THE QUESTION COMPLETELY BEFORE MARKING OR ANSWERING

I want to display text from data in url and access it using the same. Eg.

http://stackoverflow.com/questions/24888693/how-does-out-parameter-work

Notice how this page is accessed using the param how-does-out-parameter-work

Currently i am using requireJs with backboneJs in my web app. So, in my router i am routing like

siteTitle = 'Boiler Plate';

define([
    'jquery',
    'underscore',
    'backbone',
    'handlebars',
    'jcookie',
    'views/home',
    'views/404'
], function ($, _, Backbone, Handlebars, jcookie, HomePage, FoFPage) {
    var AppRouter = Backbone.Router.extend({
        routes: {
            ':*':'home',
            'home' : 'home',
            'home/:a' : 'home',
            '*whatever' : '404'

        },
        home: function (a) {
            document.title = siteTitle + ' - Home';
            homePage = new HomePage({route: a});
            homePage.render();
        },
        404: function(){
            document.title = siteTitle + ' - 404';
            fofPage = new FoFPage;
            fofPage.render();
        }

    });

    var initialize = function () {
        var app_router = new AppRouter;
        Backbone.history.start();

    };
    return {
        initialize: initialize,
        AppRouter: AppRouter
    }
});

Notice that i am getting the passed parameter a and them loading the page accordingly. Currently i am setting that parameter a as a number that is my post ID and using it accordingly. Bu if i want to pass a portion of my post's heading and access it how can i do that?

I can think of one way is selecting substring from mysql data base and based on url input but it wont help as if the parameter is how-does-out-parameter-work i can never parse it as How does 'out' (parameter) work? which is actual text in database. What am i missing?

UPDATE

the ignoring the post param is only applicable in stackvoerflow not on this site https://www.theguardian.com/us-news/2016/nov/10/hate-crime-spike-us-donald-trump-president is using something else. What am i missing?

Mercurial
  • 3,615
  • 5
  • 27
  • 52
  • 1
    Actually the `how-does-out-parameter-work` is ignored. It's just to make a pretty url. You can actually get to the same page by leaving it out. -> eg. http://stackoverflow.com/questions/24888693 IOW: It's the number part that's important.. – Keith Nov 11 '16 at 13:56
  • 1
    I assume they would have a route like `us-news/:year/:month/:day/:heading` They would then have a databse function like -> `getDoc(year, month, day, heading)` – Keith Nov 11 '16 at 14:10
  • @Keith EXACTLY! thats my question! how did they parse `getDoc(year, month, day, heading)`. since if there are brackets in the heading or special characters its not showing in url. `if the parameter is how-does-out-parameter-work i can never parse it as How does 'out' (parameter) work? which is actual text in database` – Mercurial Nov 11 '16 at 14:17
  • 1
    Really not sure what your trying to solve.. the dashes in the text is just a simple text replacement,.. In your route doing `/home/:a/:ignore` would allow you to put any text after your id, this could be a substring that you get from your database with some string replacing to sanitise the url. Your route callback could just ignore the ignore parameter, as it's the id that will be used to get your document. – Keith Nov 11 '16 at 14:26
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/127906/discussion-between-unkn0wn-and-keith). – Mercurial Nov 11 '16 at 14:27
  • What makes you think that the `how-does-out-parameter-work` slug isn't stored in the database? Why try to convert `how-does-out-parameter-work` to the title every time you need to look something up when you could convert the title to the slug and store both? The title->slug mapping almost certainly throws away punctuation and capitalization so you can't reliably unpack the slug. – mu is too short Nov 11 '16 at 18:17

1 Answers1

0

If you're attempting to follow the same process as Stackoverflow, they appear to use an Id for each question. I can only speculate what the title parameter is used for.

http://stackoverflow.com/questions/24888693/how-does-out-parameter-work

Equates to the following:

{domain}/{questions}/{questionId}/{title-string}

You can see that the title-string is an option parameter as the following will still route you to the correct question

http://stackoverflow.com/questions/24888693

The additional parameter is likely to stop duplicate Ids causing an issue in the database if the question Id counter has to be reset.

Maybe you can clarify why you need to search for a hypenated string in the databse?

Alex Wells
  • 105
  • 1
  • 9
  • Thanks for your input, but it fails to explain`https://www.theguardian.com/us-news/2016/nov/10/hate-crime-spike-us-donald-trump-president` – Mercurial Nov 11 '16 at 14:03