I'm trying to get started with a simple LAMP site however can't seem to get the Zend framework to be picked up by my local Apache instance. I started on XAMPP on Windows and have since tried a Centos 6 VM with manual Apache/PHP install, but still get the same error on both which is below. The phpinfo() works fine, as does the rest of the site.
Fatal error: Class 'Zend\Log\Logger' not found in /var/www/html/site/public/test.php on line 20
My website code is a fairly simple test to invoke a Zend framework logger which is as follows
use Zend\Log\Logger;
use Zend\Log\Writer;
echo "<p>Hello world</p>";
echo $_POST["VIN"];
phpinfo();
$logger = new Zend\Log\Logger;
$writter = new Zend\Log\Writer\Stream('php://output');
$logger->addWriter($writer);
?>
My Apache linux httpd.conf is
<VirtualHost *:80>
DocumentRoot /var/www/html/site/public
<Directory /var/www/html/site/public>
DirectoryIndex test.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
My Zend framework resides in /var/www/html/site/library/Zend, and I've added /var/www/html/site/library to the php.ini include as well.
For anyone else hitting this error you need to utilise an autoloader, something that's not mentioned on the Zend framework getting started wiki.
<?php
use Zend\Loader\StandardAutoloader;
use Zend\Log\Logger;
use Zend\Log\Writer;
require_once dirname((__DIR__)).'\library\Zend\Loader\StandardAutoloader.php';
$loader = new StandardAutoloader(array('autoregister_zf' => true));
$loader->register();
echo "<p>Hello world</p>";
echo $_POST["VIN"];
phpinfo();
$logger = new Zend\Log\Logger;
$writer = new Zend\Log\Writer\Stream('php://output');
$logger->addWriter($writer);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With