PHP & MySQL Novice TO Ninja adaptation

Hello there. I’m following through this book (for the second time) and adapting it to build a business website with a blog. I’ve reached the point in Chapter 9 where it is making an Extensible Framework, and seperating things that are generic and project specific.

In the process of following along and adapting for my site I have made some additions which include adding description and keywords tags, along with heading and subheading variables for each page. This is blurring the lines between project and framework, as I currently have references to these things in the framework sections, along with a lot of repetition. The name of the business is Room4 and I will try to explain in more detail:

Currently I have reached the point where:
-every page is accessed via index.php which includes EntryPoint.php and Room4Routes.php and calls a run() function from EntryPoint.php
-run() calls callAction() from Room4Routes.php, and contains the following code that I imagine can be made more generic*, as I’d like to have different variables for different sites:

$title = $page['title'];
$keywords = $page['keywords'];
$description = $page['description'];
$heading = $page['heading'];
$subHeading = $page['subHeading'];

and includes layout.html.php

-callAction() contains the logic for opening each page, and includes BlogController which is site specific

-BlogController is site specific and has a function for each page which contains the variables such as $title, $keywords etc as well as calling the .html.php template for each page e.g

public function rehearsal() {
        
        $title = 'Room4 Studios Hire';
        $keywords = 'external hire, rehearsal studio, recording';
        $description = 'We have a brilliant recording studio that has been acoustically designed and equipped to provide great value for money. 3 live rooms and loads of great gear.';
        $heading = 'Rehearsal';
        $subHeading = 'We have 4 acoustically designed & treated rehearsal rooms of varying sizes. The rooms also have very good sound proofing, so you won’t be disturbed by the band next–door. All the rooms come with a PA, mic sets, drum kit, bass amp & guitar amp';

        return ['template' => 'rehearsal.html.php', 'title' => $title, 'keywords' => $keywords, 'description' => $description, 'heading' => $heading, 'subHeading' => $subHeading];
    }

I would ideally like to move this information to the template for each page, but can’t figure out how to make it work, and more importantly make the code referernced further up in EntryPoint.php (denoted with *) more generic.

Any help or pointers with this would be most appreciated.

Cheers

Are you able to put your whole project on GitHub?

The honest answer to that is: ‘I don’t know’.

But I’ve had a go:

Never done much with GitHub, but keen to learn. Let me know if that hasn’t worked and I’ll have another go.

If it has worked that roughly corresponds with the book code here:

And is around page 395 in the book

Cheers

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.