SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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:

    Code:
    <?php
    
    /* 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 http://www.sitepoint.com/books/phppro1/code.php (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).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 (.*?)/(.*?)/(.*?)$
    index.php?page=$1&action=$2&id=$3

    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.

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,191
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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:

    Code:
    RewriteEngine On
    RewriteBase /phpmastery/patterns/
    
    RewriteRule (.*?)/(.*?)/(.*?)$ index.php?page=$1&action=$2&id=$3

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  6. #6
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •