Welcome Guest, Not a member yet? Register   Sign In
Ein, Zwei, Nicht DRY...
#1

[eluser]TheFuzzy0ne[/eluser]
Hi, everyone.

I'm having some trouble with a project I'm working on. The problem is that I'm requiring multiple inheritance, so it's clear to me that I've messed up somewhere along the lines. I'd appreciate anyone's input on a possible solution, as I'm not quite sure what to do.

I have the following libraries:
Auth - for handling logins, logouts and validating the current request (i.e checking to see if a user should be logged out due to inactivity).
Permissions - To ascertain whether or not the user has the relevant permissions for the current page.

I also have the following controllers:
MY_Controller (extends CI_Controller) - For general configuration and setup of the app.
Member_Controller (extends MY_Controller) - Utilises the above libraries to deny/grant access to certain content. Also generates a dynamic menu which is visible to logged in users.

Until now, this has been working fine, but the client has now requested a "Dynamic Page" feature, which basically allows users (with the appropriate permissions) to edit the content of certain pages. This is where my problem has crept in.

He would like some dynamic pages available to the general public (but, of course, only editable by users with the right permissions), and he'd also like some within the member's area.

This is where I'm coming undone. I've found the only way I can get around this (for now), is to create two dynamic page controllers, one which extends MY_Controller, and one that extends the Member_Controller (in order to ensure only logged in users have access to them, and to generate the side menu.

I admit, there's obviously a problem in my design, since I should not need to duplicate any code. Ideally, it would be nice if I could extend Member_Controller and the Dynamic_Page controllers, but obviously I can't.

I'd appreciate any feedback from anyone who can propose a solution, or even point out where the design flaw lies.

Many thanks in advance.
#2

[eluser]StevenSokulski[/eluser]
Hi there,

Forgive my ignorance, but would it be possible for you to just have your Dynamic Pages controller inherit from Member Pages. This should give you all of the capabilities of both your custom controller and the Member_Controller.

You could then implement a control in Dynamic_Pages_controller that determines where a page is to be restricted or not.

I may be over-simplifying your problem, though.
#3

[eluser]TheFuzzy0ne[/eluser]
Thanks for your reply.

That sounds like a good idea, but at the moment, if a controller extends Member_Controller, it's assumed that the user has to be logged in.

I was actually thinking of doing away with the Member_Controller completely, and moving all of the logic into MY_Controller, with a property that is defined to indicate whether or not the page is restricted to logged in users only. The down side is that it's going to require a lot of files to be updated, but I guess that serves me right for not designing the site correctly in the first place.

Many thanks again for your input.




Theme © iAndrew 2016 - Forum software by © MyBB