The Doctrine Objects are HUGE

I am converting .NET to PHP and still have a good time with the transition. I use doctrine 1.2 as my ORM and work with my models, and everything is perfectly connected. However, the problem that I am considering now is that the output objects are huge. I have a pretty simple table called USERS - it probably has 8 columns and FK for 4 or 5 other tables. I use the following code to hydrate my USERS object:

$q = Doctrine_Query::create()
->select('u.*')
->from('USERS u')
->where('u.VANITY_URL = ?',$Url_Frag);

$users = $q->execute();

print_r($users);

I see an object hydrated with my data, so that's good. However, this is also due to the fact that it looks like a bunch of metadata, which I obviously do not need. In general, the object has a length of more than 5000 lines! I am sure that there is some obvious switch that basically says "only emit such and such data", but I cannot find it in the manual of the doctrine.

Thoughts?

+5
source share
4 answers

In Doctrine2, there is a method dump()available at:

\Doctrine\Common\Util\Debug::dump($var, $maxDepth)

Performs a job similar to print_rand var_dump, but hides all data related to Doctrine.

Maybe something similar to Doctrine 1.x?

+7
source

Doctrine 1.2 "toArray". , :

print_r($users->toArray());
+6

. - 2: , 1.

-, . , doctrine_record. :

$q = Doctrine_Query::create()
->select('u.*')
->from('USERS u')
->where('u.VANITY_URL = ?',$Url_Frag)
->setHydrationMode(Doctrine::HYDRATE_ARRAY);
$users = $q->execute();

Print_r'ing hughe, doctrine ( " " ).

: http://www.doctrine-project.org/documentation/manual/1_2/pl/data-hydrators:core-hydration-methods

+1

If I'm not mistaken, objects Doctrine1.2have references to circles, so print_reither var_dumpis not a good idea on them. In fact, unless you have something like Xdebugthat that limits the depth of the recursion, you will never get output to the browser.

If you are really concerned about memory consumption, use the function memory_get_usageto examine the memory size before and after hydration.

+1
source

All Articles