user4540334
user4540334

Reputation:

php title in URL

I'm building website in php. For me is important to have pages with similar title and url. Like this: Title -> some content URL -> some-content.php

Each page has the content (articles) retrieved from mysql. Title also is retrieved from mysql.

So my question is: should I generate a .php file for each artivle or it is possible to have one php file with changing content and URL? How whould you do it?

Thanks for the attention

Upvotes: 0

Views: 135

Answers (5)

tadman
tadman

Reputation: 211740

The "piles of PHP files" design pattern fell out of style over a decade ago. DO NOT DO THIS.

Modern PHP development encourages the use of a development framework like Laravel that gives you a solid foundation for building your application.

Most of these have a robust routing system that takes care of presenting clean URLs to your visitors while allowing significant flexibility in how those URLs are handled internally. This is a huge advantage to someone concerned about how their site is organized.

Upvotes: 1

Babak
Babak

Reputation: 417

I suggest you use a framework like codeigniter which can handle the required structure of your files (MVC approach) and also helps you create SEO friendly URLs.

Upvotes: 0

Jamie Deakin
Jamie Deakin

Reputation: 156

I would definitely use one page with a changing url, title & content. It means 1 place to go when any issues occur.

Just make 1 page and use GET variables in the url to change what content is loaded.

e.g. test-page.php?content=content-id

this link is created using the id of the content from the sql table, you then get this id when the page is opened and use it to get the rest of the details from the database that will be used for your title and content.

I hope this makes sense

Upvotes: -1

Robert
Robert

Reputation: 20286

Definitly you shouldn't define new files for each article. You should have article controller in this controller you need retrieve articles from your model. In Articles you can have slug or id and pass this slug/id to template.

You could also check mod_rewrite to have nice and seo friendly urls.

Some pages to read:

Upvotes: 3

Spoke44
Spoke44

Reputation: 988

No need to make a PHP by page. In your html <head> you can change the title dynamically :

<head>
    <title><?php echo $titleFromDB; ?></title>
</head>

Don't forget to escape/protect the variable if the title can be edit by users.

Upvotes: 0

Related Questions