Practical Web 2.0 Applications with PHP – Chapter 2

Okay – I’ve pretty much made it through Chapter 2.  I won’t go over Chapter 1, because that chapter was basically just an introduction.  Chapter 2 covers developing the base classes and functionality that application will be built upon.    One of the hardest things was making sure that Zend and Smarty were installed properly and that my custom PHP.ini file was correct.  I’m using a live server on the web, so I had make absolutely sure that everything was working properly.

I did run into a few issues going through Chapter 2, but overall the chapter walked through everything really well and explained everything.  So what issues did I run into?

Issue 1
This wasn’t really an issue with the book, it was an issue with Zend and ZendLoader being deprecated and the following warning stating that it was going to be removed in 2.0.

Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in /home/…./…./zend/library/Zend/Loader.php on line 207

You can’t really have a working website if it constantly displays a warning message,  so I had to figure out how to fix this.

After several hours of trying to research the Zend Documentation concerning how to properly use the Zend_Loader_Autoloader and coming up with no success – I discovered this website/blog… Akra’s DevNotes by Rob Allen – Author of Zend Framework in Action (which I currently have on order).  He gives the fix very straight forward…

The old code –


Should be replaced with…

$loader = Zend_Loader_Autoloader::getInstance();

After I did that with some slight modifications to the variable name, everything worked fine and the warning message disappeared.

Issue 2
After creating the IndexController on page 26 it seems like the file should print out “web site home” in the browser – however instead I was receiving this…

Fatal error: Uncaught exception ‘Zend_View_Exception’ with message ‘script ‘index/index.phtml’ not found in path (/home/…./…../phpweb20/include/views/scripts/)’ in /home/…./…./zend/library/Zend/View/Abstract.php:926 Stack trace: #0 /home/…./…../zend/library/Zend/View/Abstract.php(829): Zend_View_Abstract->_script(‘index/index.pht…’) #1 /home/…./…../zend/library/Zend/Controller/Action/Helper/ViewRenderer.php(903): Zend_View_Abstract->render(‘index/index.pht…’) #2 /home/…./…../zend/library/Zend/Controller/Action/Helper/ViewRenderer.php(924): Zend_Controller_Action_Helper_ViewRenderer->renderScript(‘index/index.pht…’, NULL) #3 /home/…./…../zend/library/Zend/Controller/Action/Helper/ViewRenderer.php(963): Zend_Controller_Action_Helper_ViewRenderer->render() #4 /home/…./…../zend/library/Zend/Controller/Action/HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch() #5 /home/aboutnj/ in /home/…./…../zend/library/Zend/View/Abstract.php on line 926

The book didn’t really say that it should be working at this point, so I moved onto the database portion.  At this point I was unsure if I had set up the custom php.ini file properly with the correct paths or even if I had correctly set up Zend.  It seemed like I had since I had successfully run some of the test cases.

After I worked through the databse portion, which basically seemed to work properly and stated that the “Web site home” should be printing out – I started really looking into the issue.  After spending several hours researching on the web and making sure I didn’t miss anything in the book, I discovered that the book left out one important part of the installation of Zend.  I sort of discovered this when the book mentioned that the Zend framework expects templates to contain a PHTML extension, and I never created a PHTML file.  Going to the Zend website, I discovered that zend expects there to be /views/scripts/ directory under the include directory.

Created the subdirectory structure phpweb20/include/views/scripts and within this added the index/index.phtml subdirectory and  file.  I discovered this here – in the Zend documentation. After I had created this subdirectory, with the index.phtml file everything worked fine.

Issue 3
Okay this ended up being my problem, but it was still very frustrating.  After creating the the linkages with the  Smarty Template Engine and creating the index.tpl, header.tpl and the footer.tpl files, I was receiving this very cryptic error message…

Fatal error: Call to a member function fetch() on a non-object in /home/…./…./phpweb20/include/Templater.php on line 53

I spent about two hours on this problem, not knowing if I was getting this because of something I coded wrong or if it was because I didn’t install Smarty properly.  I tried printing out the object – first in the Templater.php class first – which didn’t print anything out.  So instead I checked to see if I could instantiate the Smarty object directly in the index.php file and print it out using print_r() and var_dump() – it was successfully being instantiated it.  Next I tried the same thing with the Templater class – with this it was not creating the Smarty class – it was showing that it was null.   Realizing that it must be a problem with something in the Templater class and not with the way I had Smarty installed – I searched on the web for the error message and found this article – Call to a member function on a non-object It was exactly the problem I was having and the person was encountering it trying to do the same thing I was  – working through the PHP Web 2.0 Applications with PHP book.  I felt like I may finally get it, the suggestions put me back into thinking that it might be the installation – but that didn’t seem right based on my other tests.  The person commented at the end saying that they had fixed it – but then didn’t give any indication of what they did – and NEVER responded to the person who asked if they could post the solution since they were having the same issue.

After this I resorted to the documentation.  It had to be because the construct() method wasn’t being called properly  since none of the values that were being created in this method were printing out when using var_dump().  I went to  the PHP Classes and Objects documentation and relooked at the way the constructor method was being called.  Needless to say it was a stupid mistype.  Instead of having two underscores and construct() – I only had one.  I had _construct() and it should have been __construct() – so the construct method was never being called.

Although it was a stupid mistake – it was a good learning experience in terms of PHP OOPs programming.  Sometimes you learn the most when things don’t work and you have to research the reason why.

Zend Classes Introduced


Posted in Books, Computers/Programming, PHP, Web Development, Web Frameworks.
Notify of

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
Greg London
14 years ago

It’s funny I’m running into the same problem. The author of the book really left a lot of unexplained things out.

I’m getting this error now after attempting to register a member

Uncaught exception Zend_Controller_Dispatcher_Exception with message Invalid controller specified

But it has nothing to do with view/scripts though. The rest of the site works, just can’t register someone.

I was thinking it was a naming convention, you know, I could’ve missed a capitalized letter for one of the action controllers.

Anyway, I’m still working on it.