Page 1 of 1

Showing content for logged/unlogged users

Posted: Wed Aug 18, 2010 8:30 am
by homerj
Hi,

This might have been discussed but I didn't find it. I have a site and some of its pages could be viewed both by logged and unregisterred users. When someone is logged additional content is shown. My question is how is the best way to implement such pages? Do I have to always check ( if(logged) show this else ... ) ? Lets assume that i keep user status in a session variable (logged - true/false).

Re: Showing content for logged/unlogged users

Posted: Wed Aug 18, 2010 9:16 am
by MindOverBody
Best way is to make modules, and upon loading page, module engine automaticly check modul privacy type.

But, if you do not use any module engine or similar, i thik if(logged) will serve purpose.
Provide some code to see if it's posible to do something else ;)

Re: Showing content for logged/unlogged users

Posted: Wed Aug 18, 2010 9:34 am
by homerj
Thanks for the reply. Actually I lied a bit - I haven't created the pages yet. I was only describing the idea : ) So could you give me a code snippet showing simple examples how to create such modules or just describe in a few lines the structure of such implementation. I imagine some kind of factory method returning some object(module) which displays content but I might be far from the truth.

Sorry for the newbie question btw :oops:

Re: Showing content for logged/unlogged users

Posted: Wed Aug 18, 2010 6:22 pm
by MindOverBody
General idea is that you have one folder where you put your modules. Something like this:

modlues/
|-- mod_news/
|-- mod_poll/
...

So, magic is that all module directories have their starting point (class), and hook (method).
That data you can store in database module table. There you can also put privacy status (public, private, etc.)

Then make module admin pages where will you be able to install/uninstal/Edit your modules.
My advice is to make method which will read modules directoriy and store all founded subdirectories (actual modules) in a static array. I hope you can see where this leads to. With that array you can check if your module is already in database or not. That is admin part job.

For the other side, to load modules, you can apply same methodology. Use method to get array of installed modules, on each check for its database privacy data and show it to the world!

With this kind of solution you have actualy plenty of room to improvise, If somebody/you want to write his modules, he do not need to handle site's code, and it is easy upgradeable.

This is just a simple solution, rest of it is on you. If u stuck, troubleshoot on PM or here.
And remember, failure is allways an option! ;)