php - ZF2 ZendLog + Doctrine2
Get the solution ↓↓↓I do not know how to configure Zend \ Log with Doctrine2. Only allows you to write directly to the database via a connection adapter or write to a file.
Answer
Solution:
May be it's too late to answer this question but better late than never.
I've found a good post which explains how to create a basic for ZF2 and Doctrine.
The approach is pretty simple :
1. Creating {-code-5} class : Create the following class in your{-code-2}
folder :
{-code-3}
The{-code-4}
function which is called by Doctrine when it finiches sending the query to the database server, is
overrided so that it could write the current query to the{-code-5}
object.
2. Configuring the {-code-5} : Add the following code in your{-code-6}
file, to make
the {-code-5} accessible to the{-code-7}
using the name{-code-8}
:
'service_manager' => array(
'factories' => array(
'{-code-8}' => function($sm) {
$log = new \{-code-14}\{-code-5}();
$writer = new \{-code-14}\Writer\Stream('./{-code-11}');
$log->addWriter($writer);
$sqllog = new \Application\Log\Sql{-code-5}($log);
return $sqllog;
},
)
),
The{-code-5}
will write data to the{-code-11}
file. So, make sure that{-code-12}
folder exists in your
application root directory.
3. Configuring Doctrine : Now you need to tell Doctrine to use the created {-code-5}. Just add the following code to your Doctrine configuration :
return array(
'doctrine' => array(
/*--------Add this code
Answer
Answer
With the above configuration of{-code-14}
and{-code-15}
, you'll get all the query data logged in the{-code-16}
file.
Please see this Sql Logger for ZF2 and Doctrine for more details.
Answer
Answer
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: object of class stdclass could not be converted to string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.