How to best organize module-determined content, which will be different for users - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: How to best organize module-determined content, which will be different for users (/showthread.php?tid=74970) |
How to best organize module-determined content, which will be different for users - bmcn - 12-02-2019 So we're adding paid modules to our site and I'm really not sure what the best way to implement this would be. The modules wouldn't really work as their own controllers since the content will be handled largely by existing controllers with minor changes to content based on if the module is active or not. I think I see a few ways to go about it:
Any advice would be appreciated, thanks, RE: How to best organize module-determined content, which will be different for users - jreklund - 12-03-2019 Depends on what the paid module are supposed to do. In case you need to have a separate Controller to handle the modules action, or a common controller can be used. But for renderingen them (boxes?) I would build a base module with common functionality like render() and extend it from all modules, so you can insert a new box anywhere on the site. You can make it so that you always include it, and in the module itself determine if it should be rendered or not. For this to work you need to pass along what type of modules the user have paid for. RE: How to best organize module-determined content, which will be different for users - bmcn - 12-03-2019 That sounds good for the boxes. One of the modules we'll be doing is to allow the owner to use their own payment gateway(s) instead of ours, that one would definitely be integrated into already existing controllers, I guess I had that in mind when I was thinking about where to put the module-only code. Right now we offer Paypal only but if the owner has Stripe then we'll be supporting that too. I guess since that wouldn't be common to all modules it would then belong in the payment-handling controller after all, and not in a place dedicated to modules. Maybe I just needed to talk/type this out, thanks. RE: How to best organize module-determined content, which will be different for users - maxxd - 12-03-2019 I'd point towards option 2, but I'm a bit confused about your con on the idea. The only time you have to change many functions using the method described is if you change function names. You could go with if/else conditionals dependent on the access level or you could create a master function object with the common functionality, then create child objects named after the access level of the current user and include those by default. For instance, something along the lines of the following: class BaseFunctionality extends CI_Controller{ public function showSection(){ $this->showTheStuff(); } } class PaidFunctionality extends BaseFunctionality{ public function showSection(){ $this->dontShowThat(); } } class PublicFunctionController extends CI_Controller{ private $_access = "Base"; public function __construct(){ if(is_logged_in()){ $this->_access = "Paid"; } } public function do_something_cool(){ $fn = "{$this->_access}Functionality"; if(file_exists($this->$fn) && is_executable($this->$fn)){ $this->$fn(); } } } |