tags:

views:

510

answers:

2

Sorry if this is a badly formed question, but I'm trying to make my web applications (using PHP) more OO. *EDIT* I'm developing the Framework myself */EDIT* Everything is great so far, I've made a Front Controller system that taps into a MVC system. The FC figures out what page you want, loads the specific page Controller (*EDIT* which extends an abstract Controller Object */EDIT*), which gets anything it needs from Models, and then calls the appropriate View. Very basic.

But now, I need to make an admin section (quasi-CMS). How does a login system fit into the grand scheme of things? Do you set controllers as needing a login? If so, how? What If you only want certain views of a controller requiring login?

Thanks in advance.

+3  A: 

Which framework are you using? I would advise using a framework such as Zend or CodeIgniter instead of rolling your own.

Anyway, the reason I ask is because these frameworks do usually have login frameworks available for them.

How it generally works is, each controller subclasses an abstract controller class. In your controller constructor, what you do is set a flag to say that it requires a valid login. Then the abstract class will check for a valid login on each request and can take appropriate action (i.e. redirect to a login controller).

Obviously you can make it more fine-grained / complicated than this, i.e. on a method-by-method basis.

Phill Sacre
it's my own framework, but it uses a system like you stated: page Controller sub-classing and abstract Controller class. Thanks for your input.
fakingfantastic
A: 

Hi, I've tried to implement Phill Sacre's respond, and I came out with something like this. Is it the right way to do it, or am I missing something? I'm a beginner in OOP, and there are some things I don't fully understand. So if I've written it wrongly, could you please correct it? Thanks in advance!

Here is the code on Pastebin

XLR3204S