Starting with Zend framework 2, the class of not found errors

I'm trying to get started with a simple LAMP site, but can't seem to get the Zend structure for my local Apache instance. I started working with XAMPP on Windows and since then I tried the Centos 6 virtual machine with manual installation of Apache / PHP, but still got the same error as the one below. Phpinfo () works just fine, like 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 pretty simple test to call the Zend frame logger, which looks like this       

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

<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>

The structure of my Zend is in / var / www / html / site / library / Zend, and I added / var / www / html / site / library in php.ini as well.

+5
source share
3 answers

- , , Zend, 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);


?>
+1

, * include_path *, include /var/www/html/site/Library not /var/www/html/site/Library/Zend.

Check: https://github.com/zendframework/zf2/blob/master/INSTALL.md

php.ini phpinfo().

0

Autoloader is really needed. If you have a path to your library included in your php.ini, you can add the following code to make Zend work as you like:

require_once 'Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
$loader->register();
0
source

All Articles