Poll: CI4: Module support?
You do not have permission to vote in this poll.
yes
88.46%
115 88.46%
no
4.62%
6 4.62%
maybe
6.92%
9 6.92%
Total 130 vote(s) 100%
* You voted for this item. [Show Results]

  • 7 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Module support?

#51
(09-25-2015, 09:17 AM)Martin7483 Wrote: Isn't that the whole point of HMVC? A request from a higher level controller should be responsible for any module called to complete the required request.
And why is a "controller" in one of my modules not a MVC controller?

I think the basic problem here is that the distinction doesn't exist in most of the current HMVC extensions. The original HMVC pattern is defined as a user interface pattern (as was the original MVC pattern), so an HMVC controller would only receive requests from the application, which, in our case, would be an application-level controller (not the router). The HMVC controllers themselves, though, would not be aware of the hierarchy, except for any hierarchy the controller itself creates to handle its request.

In other words, what you have done is closer to an application of the original HMVC pattern to CodeIgniter, while most of the previous popular HMVC extensions have applied the HMVC pattern at the same level that the MVC pattern is applied in CodeIgniter itself. However, your HMVC extension doesn't isolate itself to the user interface layer, either, it just isolates itself from the handling of requests from the router.

So, while your module's controller is an MVC controller in the sense that it serves in the role of controller for an MVC triad, it doesn't take on the role of a controller in CodeIgniter's MVC framework. We could run into a similar problem if we discussed the difference between a controller which extends CI_Controller and lives in any of our applications and the roles played by the index.php file and CodeIgniter itself as a Front Controller for our application. On the other hand, at least Front Controller is a separate pattern from MVC, so maybe we could add a level of confusion by saying that the normal (MVC) controller we previously referred to will now act as a Front Controller to your HMVC modules.
Reply

#52
As we are going a bit off-topic here, I think support for HMVC should be added to the next version of CI
Reply

#53
Big Grin 
This would be soooo powerful Big Grin

Some people that are voting "NO" call the others bad developers that don't know how to build web applications. They say it would be as simple as put the functionality you want in libraries.

Of course everything can be done in anyway... I hate "religious" talks. We have those people that say PHP sucks and compare PHP to RoR instead of Ruby... We have those people that say that WordPress sucks because it's not MVC and blabla..

For me, the modular approach is as important as using functions or classes. Why would you need to write a function if you can write the code over and over again?

As far as I can see to use MVC in an efficient way your app would have to be like:
Controller -> Model -> View
This means that you lose all the flexibility and organization of your application. Of course if the idea is to have only very simple controllers and models and views it will work fine. I might have:
/account/edit/user_id
And then the project owners decide to have one extra route that will contain exactly the same as above but also a bunch of other functionality from other controllers of your application. Eventually other functionality that need information about other controller. What will we do? Tell the project owners how we want to build the application?

Life is always changing, all should be modular, nothing should be put on extra large files, libraries aren't enough. In fact with HMVC of Wired you can have libraries, configs, and so on... inside a module. This itself can lead to more selfcontained code and force more organization of your application. I prefer to have something working good then something that is supposed to be a certain way just because it's more pure or whatever.
Reply

#54
Without getting too religious on it, your example is exactly why, in my opinion, everything should be a separate library. That way the logic is contained away from any controllers and, when the boss comes and says, "I need X, Y and Z", you just have to pull the pieces together into a new controller and you're done. The logic was already there and separate.

But - before we really start this tired debate up again, let's step back for a minute. What are both controllers and libraries? They're both simply PHP classes. That's it. They just fulfill different roles. A controller typically just directs traffic, receiving the request, gathering the parts together that's needed, whether it's from a library, model, external site, whatever. Libraries in CI3 just simply meant "any other class that wasn't a model or controller".

In CI3, the controller had a certain peculiarity about it that made it the reason that some of said we didn't recommend HMVC in CodeIgniter. Yes, I've used Wired's HMVC on many a project, and if you've every looked at the code you'll see the hacks that he had to do to make it work correctly, in large part by storing a separate controller that all others would reference since "$this" would tie back to the Controller instance, no matter what controller or model you were in.

Anyway, CodeIgniter 4 does not support HMVC by name, but we do support modular code, and you should be able to do just about everything you could with the HMVC package that your'e used to. Most of this comes through standard PHP features, like namespacing, and a PSR-4 autoloader. We've provided ways to get the views and helpers in namespaced folders, also. The primary difference is that if you want to route to a "module's" controller, you have to do it manually.

More info in this blog post.
Reply

#55
(06-26-2016, 07:52 PM)kilishan Wrote: More info in this blog post.

I think you should almost copy-paste this blog post to the userguide, there will be a lot of question about this topic. Smile
Reply

#56
@kilishan that blog post is really interesting.

And yes @orionstar I agree that this topic will lead to a bunch of questions unless it's perfectly documented and maybe in the final of the tutorial.

So... if I am within a controller what can I do? I assume I can call another module's model, another module's view but I can't call another module's controller. Is that it?
Reply

#57
There is something new on the horizon - "Puli: Universal Packages for PHP"

http://docs.puli.io/en/latest/
https://www.sitepoint.com/can-puliphp-re...velopment/
https://www.youtube.com/watch?v=YWXqET5xlzw

This manager tool seems to be a game changer candidate, it merits to be watched. Among all its features it aims to be a framework-agnostic modular solution. Packages are loaded through Composer, they contain PHP code and web-resources.
Reply

#58
(09-20-2016, 08:49 AM)ivantcholakov Wrote: There is something new on the horizon - "Puli: Universal Packages for PHP"

http://docs.puli.io/en/latest/
https://www.sitepoint.com/can-puliphp-re...velopment/
https://www.youtube.com/watch?v=YWXqET5xlzw

This manager tool seems to be a game changer candidate, it merits to be watched. Among all its features it aims to be a framework-agnostic modular solution. Packages are loaded through Composer, they contain PHP code and web-resources.

A game-changer would be something replacing Composer, not sitting on top of it.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.