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?
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…
require_once('Zend/Loader/Autoloader.php'); $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.
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/rrosetta.com/zend 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 – http://framework.zend.com/manual/en/project-structure.project.html in the Zend documentation. After I had created this subdirectory, with the index.phtml file everything worked fine.
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 PHP.net 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.