Setting Up Zend Framework 2 Autoloader

May 13th, 2014

If you’re like me, you like to dig into the belly of things and twist them to your own uses. Tonight, I’ve been monkeying around with ZF2 autoloaders, and working out how they function.

I store my ZF install in a dir (Zend/) in my include path, so I don’t have to maintain copies for each site on my server.

Some useful notes on this:

The stock ZF2 download does not include a pre-generated classmap file. To generate this, go into the default unpacked archive folder, into bin/ and run this command:

php classmap_generator.php -l "/usr/share/php/Zend/"

[code language=”php”]
// How to get an absolute path to the generated classmap file (return: /usr/share/php/Zend/autoload_classmap.php)
$classmapPath = stream_resolve_include_path(‘Zend/autoload_classmap.php’);

// How to get the autoload up and running
require_once ‘Zend/Loader/ClassMapAutoloader.php’;
$autoloader = new Zend\Loader\ClassMapAutoloader();

That’s all for tonight folks!

Which Framework?

July 21st, 2013

Learning a framework is an investment of time. You have to work out how this one structures its files, wants you to template, what levers to pull.

This is why people build their own so often. At least then it works the way you want it to.

composer more.json

July 17th, 2013

So tonight, more fun with composer. Now that I have it set up and managed to install one package, it’s on to getting enough of Zend Framework set up to make something. Since there seems to be no core package that just installs everything, it seems I have to resort to listing the arms length of packages I expect to use.

Scratch that. Tonight I’m going to try out the ZF2 skeleton application, since I haven’t used ZF2 yet.

Zend DB Query Dump

June 25th, 2013

If you ever need to see the SQL that Zend DB has created, so that you can run it manually or any other reason, here’s how to do it.

// Turn on the profiler

// Run your query
$db->update(‘someTable’, array(
‘thisField’ => 0.12551,
‘anotherField’ => ‘xxxxxxxxxxxx’
), ‘whatId = ‘ . $cdsDB->quote(‘james’));

// Output the last query
echo "\n" . $db->getProfiler()->getLastQueryProfile()->getQuery() . "\n";

// And the parameters for it

// Then turn the profiler off, unless you want to do more

And the output is

UPDATE `someTable` SET `thisField` = ?, `anotherField` = ? WHERE (whatId = 186459)
[1] => 0.12551
[2] => xxxxxxxxxxxx

WordPress - Entries (RSS) and Comments (RSS) - © 2011 Ben Dauphinee