I have the following route:
work:
class: acWorkObjectRouteCollection
options:
prefix_path: /work
module: work
model: Work
type: object
column: workname
model_methods:
object: findBySlug
As you can see, this route pulls a Work object from the db by the findBySlug method and the slug column is workname. It all works fine, but i want it to pull the Work of the connected User, so if 2 users have the same work name, it will choose the right one.
something like: ->andWhere('w.user_id = ?', $this->getUser()->getId() if you like..
of course, i can change the route url to :username/work/:workname but it looks less professional and it’s not really necessary, since each user will only be able to edit his own Work.
Any ideas how to get this done? maybe if i could access the User object in the route i could do it, but i couldn’t find out how..
Thanks in advance!
Although it’s generally bad practice, I believe this is one of the rare cases when
sfContext::getInstance()cannot be avoided. UsesfContext::getInstance()->getUser()in yourfindBySlugmethod.Before using it please read Why sfContext::getInstance() Is Bad so you’re aware of it’s problems.