Real Dreams
Real Dreams

Reputation: 18010

Variable output in Phalocn

When I use findFirst of mongo extension I can use var_dump on its out put and see actual mongo document easliy.

But when I do that on output of \Phalcon\Mvc\Collection::findFirst tens of properties and methods are outputed and I can not find desired data easily.

Is there any way to get just main data when using var_dump on this class and other classes?

Upvotes: 0

Views: 94

Answers (1)

lobostome
lobostome

Reputation: 433

One way to do this is to add a method to your collection that uses reflection and filters only the public properties:

class MyCollection extends \Phalcon\Mvc\Collection {
    public function getProperties() {
        $reflector = new \ReflectionObject($this);
        ob_start();
        foreach($reflector->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
            echo "Property: ";
            var_dump($property->getName());
            echo "Value: ";
            var_dump($property->getValue($this));
        }
        $output = ob_get_contents();
        ob_end_clean();

        return $output;
    }
}

A better formatting could probably be desired. In order to see the document:

$collection = MyCollection::findFirst();
echo $collection->getProperties();

Upvotes: 1

Related Questions