Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sails.js routes, with variables in url. ex /games/(ID HERE)

I have tried to find a guide how to get routes to work with variables in the url exemple : games/124512 and get that id to controllers in a variable.

My routes.js right now :

'/': {
    view: 'homepage'
  },

  '/games/': {
    controllers: 'games',
  }

My GamesController.js right now :

var GamesController = {

    sayHello: function (req, res) {
        res.view('homepage', {
            user : "sayHello",
        });
    },
    sayWelcome: function (req, res) {
        res.view('homepage', {
            user : "sayWelcome",
        });
    }
};
module.exports = GamesController;

I can write /games/sayHello or /games/sayWelcome but what I would like is to be able to write exemple /games/234234 or /games/234234/settings

Thanks! :)

like image 559
jerrkan Avatar asked Oct 07 '14 13:10

jerrkan


1 Answers

You can set url slugs in your routes like the link shows, i.e. /games/:id. You can access them in your contoller via by name that you set in the route, i.e. req.param('id')

like image 182
Lbatson Avatar answered Nov 02 '22 07:11

Lbatson