I've developed a web application using Zend 1.10 and would like to begin migrating to Zend 2, however I'm a bit daunted by the process based on the ZF2 online tutorials.
For Zend Framework 1, it was as simple as defining where my library was and instantiating the specific classes that I used for my project:
$library = '.:php/includes:/home/myusername/public_html/ZendFramework-1.11.11/library';
set_include_path(get_include_path() . PATH_SEPARATOR . $library);
require_once('Zend/Loader/Autoloader.php');
Zend_Loader_Autoloader::getInstance();
I'd then connect to my database using "$dbWrite = new Zend_Db_Adapter_Pdo_Mysql($config_stuff);" for example.
Is there not an analogously easy way of pulling classes from Zend 2 in a piecemeal manner as opposed to creating a full-blown Zend application?
For completeness purposes, it is worth noting an alternative to @Divey's direct, correct, and useful answer.
You could use Composer to grab individual ZF2 components. All the ZF2 components are on Packagist
The primary benefit is that you can grab just the component you need; no need to download the entire framework. Any cascading dependencies - ComponentX needs ComponentY to work - are magically detected (by ComponentX configuration) and installed.
Additionally, with Composer, you would have access to a whole ecosystem of classes - outside of ZF2 - that are available on Packagist (or just on Github itself, provided that the package is Composer-enabled) simply by adding a package to your project's composer.json
file.
Sounds like you want ZF2's Standard Autoloader. Try using this:
require_once 'Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
$loader->register();