How to Use CodeIgniter Global Functions (e.g., helper(), model()) Inside Custom "Mana |
05-23-2025, 10:15 AM
(This post was last modified: 05-23-2025, 10:17 AM by massimiliano1.mancini.)
Hi everyone,
I'm working on a project where I'm using an MVCM (Model-View-Controller-Manager) pattern. Here's how I’ve structured it:
The issue: inside the Manager classes, I’m unable to use common global functions like helper(), model(), etc., that work seamlessly in Controllers. Question: Is there a way to make these global CodeIgniter functions available inside my custom Managers classes, just like they are in Controllers? Thanks in advance!
I can't think of anything that would prevent the global helper functions from working as expected.
Here's an example of a manager: https://github.com/lonnieezell/forum-exa...anager.php While it might not serve the exact purpose you described, it definitely functions well and demonstrates the concept.
05-30-2025, 01:35 AM
(This post was last modified: 05-30-2025, 01:38 AM by massimiliano1.mancini.)
In my first post, I mentioned an issue with using global functions like helper() or model(), but I made a mistake. The inability to use them didn’t stem from the new directory structure—where I introduced a Managers folder—but rather from the test suite I was running, which wasn’t configured properly.
That said, I’d like to take the opportunity to share that the new MVCM paradigm—Model-View-Controller-Manager—is working extremely well. By using a custom helper, I can now call manager(ManagerClass) just as easily as we do with model(). I must say, CodeIgniter continues to surprise me with its flexibility, compactness, and elegance. As I mentioned in my first post, the need to introduce Managers comes from the desire to keep the codebase clean and well-organized. I'm happy to discuss this further if anyone's interested.
Hi,
What's the differences (or advantages) of MVCM compared to MVCS (movel-view-controller-service) and MVVM (model-view-viewmodel)? Just curious...
MVCM vs MVCS - it's largely a matter of naming convention and code organization philosophy rather than fundamental functional differences. The choice often comes down to the individual (or team) preferences, existing codebase patterns, and how you prefer to organize and think about your business logic. The key thing is that both recognize the same architectural need: somewhere between Controllers and Models, we should put complex business logic.
MVCS implies thinking in terms of "what service does this provide?" - like EmailService, PaymentService. This leads to more granular, single-purpose classes. MVCS may be misleading in the CodeIgniter4 context since the framework already uses "Services" to refer to its service container system, where all core classes are managed as services. Of course, we can take advantage of that - it’s just a matter of choice. MVCM implies thinking in terms of "what domain does this manage?" - like UserManager, OrderManager. This leads to broader, workflow-oriented classes. IMO, this solution is particularly well-suited for CodeIgniter4 applications with complex business requirements. MVVM is fundamentally different as it's a frontend-focused pattern that introduces a ViewModel layer between the View and Model to handle presentation logic and data binding. It solves frontend concerns, so it's popular in client-side frameworks like Angular, Vue.js, etc.
I completely agree with your points. I actually chose the MVCM approach for precisely the reason you mentioned: to avoid any overlap or confusion with the existing "Services" system in CodeIgniter4. Using "Manager" classes makes the separation of concerns clearer in my projects, especially when dealing with complex business logic, and it aligns better with how I structure domains.
|
Welcome Guest, Not a member yet? Register Sign In |