I couldn't understand completely how does the sfDoctrineRoute class works
for example, i have the following route:
Comment:
class: sfDoctrineRouteCollection
options:
prefix_path: :username/comment
module: comment
model: Comment
now, in executeNew()
method of commentActions
class, this code:
$this->getRoute()->getObject()
will return the first Comment object in my database. of course i can manually create a new Comment()
object, but then what's the benefit of usin开发者_如何学Gog the sfDoctrineRoute
class instead of sfRoute
?
In the case of executeNew, there is little/no benefit to using a doctrine route.
Consider instead the executeEdit method (update, delete and show are the same too).
A url could be like:
/comment/5/edit
(or in your case, /myusername/comment/5/edit)
$this->getRoute()->getObject() will then return comment 5 from the database - saving you the trouble of loading it (only a line or 2 of code, but still). And, a neat feature, if there is no comment 5 in the database, it automatically handles this and causes a 404 error - so you don't need to worry about that either.
精彩评论