Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

How can I prevent simultaneous access to controllers in CodeIgniter?

Hi. I'm working on a web app using the CodeIgniter framework. I want to prevent admins from accessing a certain article/page simultaneously. So if one user is editing an article, I don't want another user accessing that article/page. What should I do to make this happen? Thanks in advance.

1 Answer

Andrew McCormick
Andrew McCormick
17,730 Points

Depending on how you are set up, you'll probably want to have a 'locks' table or even add a 'locked' boolean column on your entries table.
Then whenever chooses to edit an entry you either set the lock column for that entry to true or add the entry ID to the 'locks' table. when they leave that post you set the lock to false or remove it from the 'locks' table.

Then you would want to add a check any time someone tries to edit a post which simply queries the DB to see if the entry is lock or not. If it is, then show them some message the prevents them from editing or even run the check on the list of entries, and disable the option to even edit the entry if the entry is locked.