$user variable in Task Tango app

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

20-Feb-12 11:18
Hi,
Firstly, thanks to Matt for an excellent introduction to jQuery Mobile. Your book is outstanding - so easy to read and understand.
There's just one thing I don't get when it comes to the Task Tango app...
The getListForUser function in the Todo class introduces a $user variable.
Where is this getting defined and is there a reason $userId isn't used instead?
I'm sure there's going to be a simple explanation and I'm going to look like an idiot... but I just can't understand it at the moment!
Thanks for your help.
Best wishes,
Martin
27-Feb-12 20:48
Hi Martin,

Thanks for buying my book, and for the compliment.

The $user parameter in getListForUser() is a User object (the user to retrieve the list of to-dos for). The listTodos() function in index.php calls User::getLoggedInUser() to retrieve the logged-in user as a User object, then passes this object to Todo::getListForUser().

You could rewrite getListForUser() to expect a $userId parameter instead. if you did this, you'd also need to rewrite the call in listTodos() like this:


$user = User::getLoggedInUser();
$results['todos'] = Todo::getListForUser( $user->id );


Personally I prefer to pass whole objects around where possible, as I find it encapsulates things nicely.

Hope that helped!

Cheers,
Matt

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/

 
New posts
Old posts

Follow Elated