I am learning and I got two different opinions and ways of this very trivial step. I have different pages in a project like Home, About, Contacts etc..
I did the following: An index.php files and parameters like ?page=about, ?page=contacts etc. I have a switch statement with $_GET['page'] for every parameter. For every case I include a different file for the page content.
Example:
switch ($current_page) {
case ('about'):
include VIEWS_PATH . PAGES_CONTENTS . 'about.php';
break;
case ('contacts'):
include VIEWS_PATH . PAGES_CONTENTS . 'contacts.php';
break;
default:
include VIEWS_PATH . PAGES_CONTENTS . 'homepage.php';
}
With this kind of navigation:
<a href="<?php echo BASE_URL ?>">Home</a>
<a href="index.php?page=about">About</a>
<a href="index.php?page=contacts">Contacts</a>
I read here that this way is not recommended because it is hackable and the switch statement will be very large if the pages are lot.
I was told about this practice: For every page from the project, a real physical file exist like index.php, about.php, contacts.php etc and every one of them includes its content.
And the navigation is like:
<a href="index.php">Home</a>
<a href="about.php">About</a>
<a href="contacts.php">Contacts</a>
Which way is better? If the project has 100 pages do I have to place 100 files? This means my root directory will contains a lot of files. Is there a way I store these files in some folder instead of the root dir of the project?
Thank you very much in advance for your attention and answers!
I looked a lot at CodeIgniter to see how it is managed, but it seems to complicated and understandable for me yet. I think it is something with the .htaccess files and some routings. Is it the way?