I am new to PHP and currently reading the book "PHP for Absolute Beginners". The book is currently teaching about templating and using StdClass() objects to avoid naming conflicts.
I have a template file named page.php and a home page file named index.php.
My page.php code
1 2 3 4 5 6 7 8 9 10 11 |
|
My index.php
1 2 3 4 5 6 7 8 9 10 11 |
|
The error I received is
Warning: Undefined variable $title
in C:\xampp\htdocs\ch2\templates\page.php on line 5Warning: Undefined variable $content
in C:\xampp\htdocs\ch2\templates\page.php on line 9I don't understand this as this is exactly what the book teaches, any help would be greatly appreciated and if there is a better way to use templates please remember I am a beginner so please Keep it simple!
P粉1291682062024-02-18 13:04:26
Your page.php looks a little strange. return
is not what I use when printing html. Also, you are using php and html in the php tag, which won't work. Try this:
1 2 3 4 5 6 |
|
You don’t need echo $page
in your index.php, let page.php do it.
/EDIT: There was also a typo on line 9: $pageData->$content;
I've corrected it.