Welcome Guest, Not a member yet? Register   Sign In
Admin Logic
#1

[eluser]Unknown[/eluser]
I'm fairly new to MVC in general, and I've run into a problem:

I'm re-coding a website. We have always had admin functions built-in to regular page views.

For instance, perhaps there is an image or blog post displayed with a title and caption. Admin-level users will have an option displayed to edit the title/caption, and perhaps delete the entire image/post. Regular users will have the image, title and caption displayed, but without an option to edit them.

Hopefully I'm not a dunce, but I can't figure a way to retain this functionality without putting the logic directly into the view. I'd rather not, if there's a better option, so I appeal to the experts.

I'm also not totally opposed to removing the functionality and replacing it with a better system, however the site has thousands of moderated objects and I think it's likely the best system for our particular website.
#2

[eluser]jedd[/eluser]
Hi sejje and welcome to the CI forums.

[quote author="sejje" date="1259127065"]
For instance, perhaps there is an image or blog post displayed with a title and caption. Admin-level users will have an option displayed to edit the title/caption, and perhaps delete the entire image/post. Regular users will have the image, title and caption displayed, but without an option to edit them.
[/quote]

This seems to be a fairly commonly perceived Best Practice way of doing things.

Quote:Hopefully I'm not a dunce, but I can't figure a way to retain this functionality without putting the logic directly into the view. I'd rather not, if there's a better option, so I appeal to the experts.

Obviously some logic will need to be in your view - as it was in your legacy system.

The distinction is whether it's business logic or display logic - as the latter is considered kosher for view use. The trick is to pass a variable to your view that denotes whether the admin functions are visible or not - the variable is determined and set by controller, of course.
#3

[eluser]Unknown[/eluser]
Thanks for the welcome! I'm kind-of excited to be here, but I'm trying to contain my giddiness.

Your response makes perfect sense. Thank you kindly.
#4

[eluser]jedd[/eluser]
Feel free to gracefully succumb to the giddiness.

I feel I should add, just in case it isn't obvious, that your security remains at the controller level - so any URL's in your views that only an admin should see need to have some security checks bundled in the relevant controller/methods that ensures the user is, in fact, an admin.

The view logic - whether to show a 'delete' button or not - then becomes no more interesting than the logic that determines whether to show a sub-heading in green or blue, say.




Theme © iAndrew 2016 - Forum software by © MyBB