简体   繁体   中英

How should I structure my codeigniter controllers?

PROBLEM AT HAND:

I am creating a "micro web site" with no more than 10 pages. The login form is on the home page when a user isn't signed in. Here is a quick break down.

Public Access Pages:

  • Home Page (non-member)
  • Info Page
  • News Page
  • Registration Page

Member Access Pages:

  • Home Page (member version)
  • My Account Page
  • Enter Contest Page

Potential Solution:

I am not sure the best solution for my controllers. I was thinking of using 2 controllers, a public controller, and a member controller. My default controller would be public. The constructor will check if a user is logged in, and if they are, redirect them to the member controller:

redirect('member')

The member page will be loaded, which has a few more links than the public page. And when a use clicks to enter contest, the member constructor makes sure they are logged in, and then shows the contest view.

Is this how it should be done to have privileged access. I will also add an admin page for the administrator to change the prizes. So there will be 3 privileges.

Thanks!

You did great to name all of your view files there. Now, other than the 2 home views, you can create a controller for each of those views and a model for the controllers that need access to a database.

In the construct for each of your privileged controllers, check the person's access level. If they don't have access for those pages, redirect them somewhere else or possibly load a view with an error message.

With the home view, it's the same except you are just deciding whether to load the non-member or member home page depending on whether they are logged in or not. Ie you don't really need a redirect on failure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM