views:

335

answers:

2

To clearly separate the Controller and View layers, I do not longer want to pass full objects to my views. Instead I want to pass only arrays and objects that contain the data but do not have any methods. Otherwise a view script would be able to delete Doctrine records or traverse in the object tree to data that was not intended for the view.

+2  A: 

I believe $collection->toArray() should do what you want

See http://www.doctrine-project.org/documentation/manual/1_1/en/working-with-models:arrays-and-objects

Mike B
I know this one but find arrays unhandy. Is there a way to generate an object that contains the the data but not the methods etc.?
Alex
You will lose a lot of the getter/hydration magic that doctrine implements. In the long run you're really limiting yourself.
Mike B
+1  A: 

You're doing something that is completely senseless. What's the point of that? You won't stop yourself/other programmers from illegal operations in the view layer. Maybe you won't be able to do $obj->delete(); but Doctrine_Query::create()->delete()->from('ObjectTable')->execute(); will be still available.

Pass object to the view and just don't execute such methods on them - that's what you should do.

Crozin