steampixel/simplePHPRouter

Question about Page Title and Page Description (SEO)

AndrewMarkUK opened this issue · 3 comments

I really like this class. I am testing at the moment and I am successful at getting the content to appear in the body of the page, but wondering about the best method of populating the Page Title and Page Description, as I am calling the script in the body, maybe this is the wrong way.

Can anyone advise?

Hi,
The routing must be done before anything (before even displaying anything). To build the actual page, it's after.

Thank you. If I understand your reply, I believe you mean something like this...

include(route.php);
use Steampixel\Route;

/* Then one of these of each and every route? */

Route::add('/',function(){
include('assets/php/config/index.php'); // Database Connection and Other Configs
include('models/index.php'); // Model for Index
$view = 'views/index.php'; // View for index (setting path)
include('html.php'); // html page including $view (echo) in the body
});

I have done this and it now works.

To do this for each route, this is efficient?

Hey @AndrewPaget,

only for completeness: Take a look at this project. It is using the same router. You may interested in the Component:: class.

You should create a PHP-view-file called "body.php" or "layout.php". Than you can easily push the title and other vars to your layout:

Route::add('/',function(){

include('assets/php/config/index.php'); // Database Connection and Other Configs
include('models/index.php'); // Model for Index

echo Component::render('layout', ['title' => 'Mytitle']);

});

https://github.com/steampixel/simplePHPPages