admin管理员组

文章数量:1024675

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",
        });
    },
    sayWele: function (req, res) {
        res.view('homepage', {
            user : "sayWele",
        });
    }
};
module.exports = GamesController;

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

Thanks! :)

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",
        });
    },
    sayWele: function (req, res) {
        res.view('homepage', {
            user : "sayWele",
        });
    }
};
module.exports = GamesController;

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

Thanks! :)

Share Improve this question asked Oct 7, 2014 at 13:33 jerrkanjerrkan 971 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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')

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",
        });
    },
    sayWele: function (req, res) {
        res.view('homepage', {
            user : "sayWele",
        });
    }
};
module.exports = GamesController;

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

Thanks! :)

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",
        });
    },
    sayWele: function (req, res) {
        res.view('homepage', {
            user : "sayWele",
        });
    }
};
module.exports = GamesController;

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

Thanks! :)

Share Improve this question asked Oct 7, 2014 at 13:33 jerrkanjerrkan 971 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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')

本文标签: javascriptSailsjs routeswith variables in url ex games(ID HERE)Stack Overflow