not sure if I'm asking too many questions on stackoverflow lately but I feel that the Zend Framework documentation is appalling. It seems like the examples are very vague and nothing like what is used in the real world. They encourage use of framework for tidy and organised code and then don't mention how it should be followed :D
So anyway! In the old application that I'm currently migrating across to Zend, I'd have a function called register like:
function register($username, $password, $email, $etc) {
// Do stuff
// Insert $email and other stuff into `user_profile` table
// Insert $username and $password into the `user` table
}
But now with Zend... I've been following their Guestbook tutorial for getting started and I have the following models: User
, UserMapper
.
And I have DbTables for every single table in my database like so: User
, UserProfile
.
So I like the functionality of when you register, you build up a User object and then call save
on the mapper which writes the object to the database but the thing is, some of those user pieces go into the user profile table. The example on the guestbook application is that within UserMapper you only pull in the one table (User) and write to that... well I mean I could just do something like:
// Insert or Update data to user table
$this->getDbTable()->insert($user_data);
// Insert or Update User Profile data
$this->setDbTable('UserProfile');
$this->getDbTable()->insert($user_profile);
But that just seems a bit.. hacky. What is the actual recommended way of dealing with multiple tables?
Also, if I have custom queries... am I meant to put them into the created DbTable
class or into the UserMapper
class? I'm not really seeing what extending the DbTable is actually for. All the guide says is to do it and it doesn't really explain the benefits/reason/uses as to why you're doing it.
Thanks, Dom