0
votes

I'm hoping someone can spot what I've forgotten to do. Here are my steps:

  1. Downloaded and unpacked the ZendFramework-2.3.5 into /usr/share.

  2. Updated include_path in my php.ini file to include '/usr/share/ZendFramework-2.3.5/library' per the INSTALL.md, and restarted Apache to confirm the path is set (now ".:/usr/share/php:/usr/share/ZendFramework-2.3.5/library").

  3. Created a test script in my web document root (using the class 'CamelCaseToUnderscore' as an example):

    use Zend\Filter\Word\CamelCaseToUnderscore;

    $filter = new CamelCaseToUnderscore();

    echo $filter->filter('BigsAndLittles');

...and I get the fatal error "class 'zend\filter\word\camelcasetoseparator' not found".

In order to do use Zend classes like this, do I need to do some additional configuration or create an autoloader or something to find them? Seems like this should have worked. If I include the CamelCaseToUnderscore.php file in a require_once statement, then I get a fatal error that it's parent class doesn't exist (CamelCaseToSeparator.php). What am I missing?

1

1 Answers

1
votes

You can use require 'Zend/Mvc/Application.php' to test if your include path is correct, but you will need an autoloader:

http://framework.zend.com/manual/current/en/modules/zend.loader.standard-autoloader.html.

You can find an example here (lines 18-20): https://github.com/zendframework/zf2/blob/master/demos/Zend/Feeds/consume-feed.php

I strongly suggest using composer as it will save you a lot of time troubleshooting your include paths, but it also allows you manage version better. It makes it easier for other developers and to deploy your code.

Starting with composer is very easy, just install it and create composer.json:

https://getcomposer.org/doc/01-basic-usage.md#composer-json-project-setup

Run:

composer require zendframework/zendframework

Composer will download all libraries to vendor folder and will generate an autoloader, all you have to do is to include

require 'vendor/autoload.php';

https://getcomposer.org/doc/01-basic-usage.md#autoloading

Most popular PHP frameworks use composer for managing dependencies: https://github.com/zendframework/zf2/blob/master/composer.json https://github.com/symfony/symfony/blob/2.7/composer.json