Sitepoint Book: PHP Master

I’m having trouble getting a lot of the code in this book to work, particularly in the API’s chapter. It seems the code is meant more for demo rather than a working example or for exercise.

The latest problem I’m having is with the Building a RESTful Service. The first thing the code does is instantiate a class called Request. None of the previous code examples create this Request class so I assumed this was a native PHP class. I was wrong in this assumption as the script is returning an undefined class error.

Should I not be trying to replicate the code in this book?

The associated text states that it iRequest is simply an empty class. The excerpt from the code on page 117 is from the index.php file while the class is defined within the request.php file which contains:


/* vim: set shiftwidth=2:*/
class Request { }

As the book only contains excerpts from some of the code being discussed you really need to the corresponding code archive in order to be able to properly work with the code - see (or read page xxiii in the front of the book and follow the instructions there that will get you to that web page where you can download the archive).

I’m still having troubles with the code in this book.

Thank you, Felgall, for the link, but I’ve been using the code base since page 1. I’m sure a lot of the difficulties I’m having are due to my own error, but overall this book has really dropped the ball when providing code examples the reader can work with.

Not only are there several discrepancies between the book code and the downloadable code, the author gives little to no explanation how to test the code examples.

Most of the SPL examples ran with little trouble. But now I’m on the MVC section of chapter 4 and none of the code excerpts even instruct you in which files the code should be placed.

The section starts off with code for a mod_rewrite, which I assume can only be placed in a .htaccess file. Yet there’s no .htaccess file included in the codebase, as there was in the REST example.

I’m getting an Internal Server Error when testing the .htaccess.

Here’s the code taken directly from the book:

RewriteEngine On
RewriteRule (.?)/(.?)/(.*?)$

My project is in wamp/www/phpmastery/patterns. I’ve tried placing the .htaccess back and forth between all these directories, and have also tried tinkering with the url path in the above code to match my system. I’ve also confirmed mod_rewrite is enabled on my server.

WAMP and mod_rewrite don’t play nicely together, what you will need to do is set the RewriteBase so your .htaccess file looks like the below:

RewriteEngine On
RewriteBase /phpmastery/patterns/

RewriteRule (.*?)/(.*?)/(.*?)$ index.php?page=$1&action=$2&id=$3

Placing the htaccess file in my project root folder and using the RewriteBase as you suggested worked! I can move on with my life now. Big thanks!

Happy New Year!

I just got done with “PHP & MSQL - Novice to Ninja”, which was fantastic! I then followed the recommendation to get “PHP MASTER - Write Cutting-edge Code” and I am left floundering.

With novice to ninja I was empowered and actually built and ran from there but with master I soon hit a wall…can anyone suggest how I can utilize/test the code in a meaningful way. I am sure this book is crazy helpful I just don’t know how to implement all the heavy theory into my code.

Any help would be greatly appreciated.