This may be due to a gap in my understanding of the PHP Object-Oriented model, but bear with me and see if you find it makes any sense/any glaring errors. Anyways, in a MVC app I have two controllers, Post.php and Thread.php. In the Thread controller I have a public method mark_as_read() which does as you could guess. It marks a thread as read (insert row in DB) or updates the time of the last view in the database. In the Thread controller I can call it easily by doing:
$this->mark_as_read($user_id, $thread_id);
However, in the Post controller I also want to be able to mark a thread as read, specifically when I make a new post and I don't want the database to reflect that the user hasn't read their own "new" post. First question: how can I call the mark_as_read() method on a thread from the post controller?
Anyways, I tinkered around and solved this problem in a way which seems very bad to me by instinct. There is a Base controller that both the Post and Thread controllers inherit from. I moved the mark_as_read() method into the base controller, and now I can mark a thread as read by calling the same:
$this->mark_as_read($user_id, $thread_id);
From ANY controller! The reason this seems really bad to me is because I have other controllers where I'm not sure I really want to mark threads as read, and instinctively it doesn't feel like it belongs there. I am pretty sure I'm doing this wrong... so question two: how do I do it the "right" way? I'm using Laravel 3 (http://laravel.com/) but this seems like a general OO PHP question, not specific to the framework.