Reporting with Zend_Tool and Zend_Log
This video uses a collection of powerful PHP libraries in order to illustrate how easy it really is to build a command-line tool for reporting against XML files. We start off by logging visitor statistics in the controller into a log file with Zend_Log. Once data has been collected, we’re then able to utilize SimpleXML, Zend_Date and the Zend_Tool component to build out a very simple reporting tool. This is of course just an example of what’s possible. What comes to mind for me is building a cron job for generating reports based on the zf.sh executable, or even just doing backups at the command-line with the help of a fully integrated Zend Framework installation.
I’ve noticed that configuration information isn’t properly loaded into Zend_Tool and am still trying to figure out the design decisions there. You’ll notice that I was having some timezone issues with regards to Zend_Date and it seems that specifying a timezone in my application.ini file didn’t resolve the issue.
Grab a copy of the project or browse the repository.
Enjoy!

Hi Jon,
I’ve noticed that you had some problems with the ‘require_once’ when loading your custom classes.
You might want to do this in your ‘application.ini’ files
autoloaderNamespaces.joni = "Joni_"
Zend application should be able to take care of class autoloading when this line is added to your application config file (i.e. application.ini)
Hope this helps! Keep up the good screencasts!
Great as always. Thanks
PS. NetBeans (6.9 Beta) has built in Zend Framework now! They also use a provider for the integration.
previously I have used
autoloaderNamespaces.namespace[] = “Zucchi_”
to resolve my namespacing
Dunno If this is of any help
Is there any reason to not use the Zend_Config_Xml component to traverse the XML
Also your timezone error looks like its thrown by “date(‘e’)” which you could have changed to a Zend_Date object to resolve
Good call Matt. Thanks
Hi Jon,
I’m not sure if this the best way of handling this, however, I managed to get around the autoloading issue you mentioned by setting up a custom Zend_Application bootstap for use with all CLI / Zend Tool utilities.
I did this by adding a __construct to my manifest file and starting up my application only registering namespaces I want for CLI activities. Eg..
public function __construct()
{
define(‘APPLICATION_PATH’, dirname(__FILE__) . ‘/../../application’);
define(‘APPLICATION_ENV’, ‘production’);
require_once APPLICATION_PATH . ‘/../library/Doctrine/Doctrine.php’;
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . ‘/configs/application.ini’
);
$application->bootstrap(‘cli’);
}
And in my Bootstrap…
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initCli()
{
// CLI / Zend Tool specific loaders / inits
}
}
i dont know why but with:
$writer->setFormatter(new Zend_Log_Formatter_Xml(‘visitor’,$this->getFormat()));
it logs only the first row:
200
when i remove $this->getFormat() so its only
$writer->setFormatter(new Zend_Log_Formatter_Xml(‘visitor’));
it logs all the data $value….
Hi Jon,
First of all, I have to thank you for your zendcasts.
About the problem with the require_once, it’s useless to define anything in the application.ini because this file doesn’t seem to be read by the CLI project.
The solution appears to append in the .zf.ini a definition for both provider and manifest:
basicloader.classes.0 = “ZC_Tool_VisitorProvider”
basicloader.classes.1 = “ZC_Tool_Manifest”
I found this solution at this link : http://chetzit.com/blog/zend-framework/12.html
Hope this will help
cool
The best way to process XML data for display is by using XSLT. I recommend installing Apache-Xerces2-J which has class files that allow you to process XML using SAX (event) or DOM (tree) for display. This would make for a great third tutorial which would also allow you to introduce Zend_Bridge.