I'm trying to understand when is the appropriate time to use Doctine_Table classes and which methods to store there vs. in the regular model class file.
Also, is it good practice to use the findBy* methods?
I'm trying to understand when is the appropriate time to use Doctine_Table classes and which methods to store there vs. in the regular model class file.
Also, is it good practice to use the findBy* methods?
Use methods in the model class that operate on an instance of that model - a user record that you've retrieved, a blog post etc. For example, you may have a setPassword()
method on a user record, which sets the password for that user using your own algorithm, or a getTitleUppercased()
method on a blog post which returns the blog title but uppercased.
Methods on the table class are used for operating on the table as a whole - generally, you'll find query methods here that aren't available via the Doctrine magic methods. Queries that involve specific joins, specific parameters (eg WHERE date > NOW() AND foo.bar < 5
) should go in here.
It's good practice to use the findBy*
methods if your query is simple - don't reinvent the wheel. Note that these are quite specific, so it's great for things like findOneByEmail('[email protected]')
, but if you need to be more specific, move your query into the table class into its own method.