Welcome Guest, Not a member yet? Register   Sign In
Best way to add/edit a listing
#9

[eluser]Rick Jolly[/eluser]
[quote author="CIfan1000" date="1225576684"]
What I also noticed is that the action url of the form is departments/save, but the views are loaded in the add or edit functions. Maybe I don't fully understand the code, but is seems to me that when the user hits Submit, the view including the form is not reloaded, which it would have to be if there were validation errors.
[/quote]
Well, actually in that example the add or edit methods are called to redisplay the view if validation fails.

[quote author="CIfan1000" date="1225576684"]
I hadn't thought as yet of checking that the record is actually in the db before trying to retrieve the whole record - so thanks again for another good suggestion.
[/quote]
I wouldn't check if a record exists before getting the record, as that is 2 queries. What I'd do is validate that the id is a positive integer first (that could be done with a route or in the code), then get the record. But there needs to be some logic to handle the case where no record is returned (in the case of an invalid id). For example, redirect, show an error in the view, or show a 404 page. The code example doesn't handle that case.

[quote author="CIfan1000" date="1225576684"]
Also, I store the userID with each listing (one has to) and I am thinking of checking the session based userID of the actual user against the userID in the listing, for security purposes, in case the session has been hijacked. What do you think?[/quote]
I'm not sure that I understand, but if the logged in user can only access listings by their id, then you'd always need to include the user id from the session in the query. You wouldn't have a choice.


Messages In This Thread
Best way to add/edit a listing - by El Forum - 10-31-2008, 06:06 PM
Best way to add/edit a listing - by El Forum - 10-31-2008, 06:30 PM
Best way to add/edit a listing - by El Forum - 10-31-2008, 06:47 PM
Best way to add/edit a listing - by El Forum - 10-31-2008, 09:30 PM
Best way to add/edit a listing - by El Forum - 11-01-2008, 03:15 AM
Best way to add/edit a listing - by El Forum - 11-01-2008, 05:48 AM
Best way to add/edit a listing - by El Forum - 11-01-2008, 10:13 AM
Best way to add/edit a listing - by El Forum - 11-01-2008, 10:58 AM
Best way to add/edit a listing - by El Forum - 11-01-2008, 12:06 PM
Best way to add/edit a listing - by El Forum - 11-01-2008, 06:23 PM
Best way to add/edit a listing - by El Forum - 11-01-2008, 06:24 PM
Best way to add/edit a listing - by El Forum - 11-01-2008, 07:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB