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.
views:
335answers:
2
+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
2010-05-18 07:03:25
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
2010-05-18 13:23:42
You will lose a lot of the getter/hydration magic that doctrine implements. In the long run you're really limiting yourself.
Mike B
2010-05-18 14:28:52
+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
2010-05-18 14:07:28