Reputation: 179
I'm trying to make a mashup using Php and Last.fm api. But I've got some questions:
1 - How can I organize the code? Because the webapp'll do different thing and each one has it own code (file.php) but I don't like to see it in the url Ex: www.example.com/core/similar.php or www.example.com/core/get.php but I'd like to always see "www.example.com".
2 - There are any guidelines to follow when programming a webapp?
Upvotes: 0
Views: 238
Reputation: 5204
First of all, you can set up the webserver to rewrite the urls based on patterns. I do not know which webserver you're using, so look it up. Apache is popular, and if you have mod_rewrite
, you do the rewriting in the .htaccess
file.
On the other hand, you may as well define a index.php
file, which can function as a routing script, showing the relevant content to the user.
In the simplest form, it may look like this:
<?php
switch ($_GET['page']) {
case 'get':
require('core/get.php');
break;
case 'show':
require('core/show.php');
break;
default:
require('core/welcome.php');
}
Though, normally this is handled in a much more structured way, such as the MVC pattern.
Upvotes: 2
Reputation: 64915
It depends on the server you're using, for example, in Apache you can use .htaccess file to map which .php file will serve which URL.
The second question is too broad.
Upvotes: 2