Hey!
So I'm trying to make a simple site where I would be able to make posts,
the point is that multiple people would have accounts and could make posts.
I have accounts and posts all figured out, but struggle to automatically give a user its own page and their posts their own page. For example if there was a user named Bob on my website, there'd be a link like www.mysite.com/users/bob and you'd see the user profile with the information taken from his account (mysql). Under that he'd have posts (Like a blog), for example he wrote about his day at the beach, I'd like to get it to automatically create an url for it like www.mysite.com/users/bob/my-day-at-the-beach
with 'my day at the beach' being the title.
Thank you.
Sincerely,
Worldofwar
Automatic new URL for new content
Page 1 of 13 Replies - 939 Views - Last Post: 04 September 2013 - 01:36 PM
Replies To: Automatic new URL for new content
#2
Re: Automatic new URL for new content
Posted 04 September 2013 - 01:20 PM
It depends on the server you’re running. on this level you can make the server feed your script with the necessary variables created from the URL (btw. no-one says that an URL must map to a file location).
example:
example:
// using Express on a Node.js server
// omitting all required settings for simplicity
app.get('/users/:user', function(req, res) {
res.render('user_profile', /* get data from DB using req.params.user */);
});
app.get('users/:user/:title', function(req, res) {
res.render('user_blog', {
title: req.params.title.split('-').join(' '),
name: req.params.user
});
});
#3
Re: Automatic new URL for new content
Posted 04 September 2013 - 01:21 PM
A little more digging resulted into a specific tutorial on how to do this.
If anyone has the same question, here is the link: http://net.tutsplus....or-pretty-urls/
Didn't see your post, the example you posted goes far beyond my knowledge. But I'll take a look at how this works
thank you very much.
If anyone has the same question, here is the link: http://net.tutsplus....or-pretty-urls/
Dormilich, on 04 September 2013 - 01:20 PM, said:
It depends on the server you’re running. on this level you can make the server feed your script with the necessary variables created from the URL (btw. no-one says that an URL must map to a file location).
example:
example:
// using Express on a Node.js server
// omitting all required settings for simplicity
app.get('/users/:user', function(req, res) {
res.render('user_profile', /* get data from DB using req.params.user */);
});
app.get('users/:user/:title', function(req, res) {
res.render('user_blog', {
title: req.params.title.split('-').join(' '),
name: req.params.user
});
});
Didn't see your post, the example you posted goes far beyond my knowledge. But I'll take a look at how this works
thank you very much.
This post has been edited by worldofwar: 04 September 2013 - 01:23 PM
#4
Re: Automatic new URL for new content
Posted 04 September 2013 - 01:36 PM
worldofwar, on 04 September 2013 - 10:21 PM, said:
the example you posted goes far beyond my knowledge.
usually you have two (main) separate softwares, one for the HTTP server (Apache, Nginx, ...) and another for the scripting language (PHP, ASP), resp. compiled programmes (C, C++).
that example is using server-side Javascript, which uses JS for the HTTP server and the script. (the server software is Node.js using a couple of plugins (like for example Express for setting upt the HTTP routes, Jade (DoT, AngularJS) for rendering HTML, less (stylus) for rendering CSS, mongoose for connection to a MongoDB database, etc. pp.))
the main advantage is that you can code both server- and client-side in the same language (there are even templating engines that work on client and server alike (i.e. it doesn’t matter if you load a page or use AJAX)).
Page 1 of 1

New Topic/Question
Reply


MultiQuote


|