views:

516

answers:

2

I think I must be missing something obvious here. I have Doctrine and Zend Framework set up together. In the bootstrap.php file I have the following - based on the Doctrine documentation for using the profiler:

$profiler = new Doctrine_Connection_Profiler();
$conn = Doctrine_Manager::connection();
$conn->setListener($profiler);

(...)

$frontController = Zend_Controller_Front::getInstance();

(...)

$query_count = 0;
$time = 0;
echo "<table width='100%' border='1'>";
foreach ( $profiler as $event ) {
    if ($event->getName() != 'execute') {
        continue;
    }
    $query_count++;
    echo "<tr>";
    $time += $event->getElapsedSecs() ;
    echo "<td>" . $event->getName() . "</td><td>" . sprintf ( "%f" , $event->getElapsedSecs() ) . "</td>";
    echo "<td>" . $event->getQuery() . "</td>" ;
    $params = $event->getParams() ;
    if ( ! empty ( $params ) ) {
          echo "<td>";
          echo join(', ', $params);
          echo "</td>";
    }
    echo "</tr>";
}
echo "</table>";
echo "Total time: " . $time . ", query count: $query_count <br>\n ";

There are no errors, the profiler output at the end only prints: "Total time: 0, query count: 0".

The connection is definitely working, as the queries get executed - I've got a SELECT fetching a bunch of items using Doctrine_Query::create() and it's execute method.

A: 

What is in the $profiler array before you start running it?

It's basically empty:Doctrine_Connection_Profiler Object( [listeners:private] => Array( [0] => query [1] => prepare [2] => commit [3] => rollback [4] => connect [5] => begintransaction [6] => exec [7] => execute ) [events:private] => Array( )
YiSh
+1  A: 

There are better approaches, but this may be a better starting point.

Assuming the connection and profiler are setup during bootstrap, there are several initial attempts to develop a Doctrine resource plugin see http://www.nabble.com/RFC%3A-ZendX_Doctrine-to23454552.html and http://www.nabble.com/Autoload-models-with-no-namespace-to23387744.html, you could do something like this in a controller/action:

http://pastie.org/475589

And then something like this in a layout or view script:

http://pastie.org/475593

Matthew Lurz
Thanks for the links, it's good to see some work being done behind proper integration of ZF and Doctrine.
YiSh