I am trying to use Twig
templates to display some objects fetched with Doctrine 1
. I face an issue when accessing a relation declared with hasMany
in the setUp
function of the User
class. In my PHP code I can do a $user->Instance
without any issue but if I pass $user
to the template and try to do a user.Instance
an exception is raised:
Doctrine_Record_Exception' with message 'Unknown method User::Instance'
How can I solve this?
Thanks,
PS: using user.get('Instance')
seems to work though I would of course prefer to avoid it
To avoid this you have to define all the getters you want to call in the template because doctrine uses "magic methods" (__call()-method) to provide you the getters and setters.
E.g. for property "firstname":
Twig checks whether the method "getFirstname" exists but there is no method "getFirstname" defined in your model.
Here you find a patch to tell doctrine to genrate the getters and setters: http://coolsoft.altervista.org/en/blog/2009/03/how-make-symfonydoctrine-generate-accessors