HMVC for Yii2.0
#2
Posted 14 June 2011 - 03:03 PM
Am I missing something? What does HMVC offer that modules doesn't feature?
#3
Posted 14 June 2011 - 03:09 PM
#4
Posted 14 June 2011 - 03:20 PM
that sounds like modules to me, too ...
http://www.yiiframew...n/basics.module
you can call modules from other modules if you want to ...
--iM
The maker rests. The wheel’s in motion.
-- Imre Madách
check out Yii2 Theme Factory at https://yii2.themefactory.net
#5
Posted 14 June 2011 - 03:28 PM
- There are no real advantages over current architecture… well maybe there are for some cases when you need a widget to be self-contained with it's own actions and URLs.
- It will add complexity. A lot of complexity.
- It will possibly slows things down for cascade file system and stuff.
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#6
Posted 14 June 2011 - 03:29 PM
@samdark it enables you to reuse code from other controllers without duplicating it, but yes , it could slow down the application if you use it
#7
Posted 14 June 2011 - 03:43 PM
It would be a good idea if it was a distributed hierarchy, i.e. a cloud, but I don't think it's such a good idea..
After all it was in PAC upon which MVC is based/derived.
You could make something even better by creating either modules with REST or SOAP interfaces/services or separate applications (which could be run on the same or different servers) which would scale even better I think.
Luckily, Yii has web services and REST built right into it, so it should be more straight forward than the Kohana code in that article.

It doesn't belong in Yii, however. IMO.
#8
Posted 15 June 2011 - 08:38 AM
What is missing - is that if I need to capture output I should explicitly use output buffers and if I need to pass GET parameters to the route I call then I also should do this explicitly, something like this:
action forwardAction() { $temp = $_GET; $_GET = array('param1'=>'xxx', 'param2'=>'yyy'); ob_start(); //second parameter = false - do not exit $this->forward('target/action', false); $response = ob_get_clean(); ... echo $response; }
#9
Posted 22 June 2011 - 02:30 AM
What I find interesting:
Controllers: List->default List->category List->search Product->default Product->reviews etc. Urls: http://www.shop.com/list/ http://www.shop.com/list/category http://www.shop.com/list/category/4 http://www.shop.com/list/search/query.hammer http://www.shop.com/list/category/4/product/2524 http://www.shop.com/list/search/query.hammer/product/2524 http://www.shop.com/product/2524 http://www.shop.com/list/search/query.hammer/page.4/product/2524 http://www.shop.com/list/category/25/page.42/product/11945/reviews http://www.shop.com/list/search/query.big+fork/sort.price/order.asc/page.18/product/114/review http://www.shop.com/product/1545/reviews
Hierarchical UI's need to be able to pass data down the hierarchy. I played around with this a while back using Zend if anyone is interested?
#10
Posted 22 June 2011 - 02:42 AM
Attached File(s)
-
nuui-template.zip (108.13K)
Number of downloads: 28
#11
Posted 25 July 2011 - 05:01 AM
#12
Posted 09 November 2011 - 01:50 PM
I'm new to Yii and have not dealt with widgets or modules yet as I am getting my first experience through the Agile web dev with Yii book and am just now on chapter 8.
I want to ask basically the same question but include my understanding based on the Codeigniter implementation. It appears that this same functionality is just not being called hmvc in Yii but to help clarify it here's how I have used the hmvc extension in codeigniter.
In Codeigniter
Top of the hierarchy:
application/controller/site.php
application/model/site.php
application/view/site.php
Login module
application/modules/login/controllers/login.php
application/modules/login/models/login.php
application/modules/login/views/login.php
Assuming the default framework has been modified to include the hmvc extension,
the login module can simply be copied from one application to another
and work out of the box because it is fully self contained.
The user can get to the login module by either of the two
http://localhost/site/login (assuming the login method of site controller loads the login module)
or by
http://localhost/login (due to the way the hmvc checks the modules folder and autoloads the module).
The main site controller can send/recieve data to and from the login module and
the login module can send/recieve data to and from the main site controller.
To my understanding the purpose of this is so the login module can include
functionality or views from the main site and visa versa.
The login module can be included in the main site view as a sidebar widget. So if you created
a self contained calendar module you could have the main site view show the calendar as a sidebar widget.
So the question for me is, can this level of extendability, module reuse, and control
be accomplished with modules or widgets in Yii? Is it really just a matter of different terminology for the same thing?
Thanks
#13
Posted 09 November 2011 - 06:30 PM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#14
Posted 17 January 2012 - 12:28 PM
#15
Posted 23 January 2012 - 03:17 PM
A true implementation of HMVC uses the Chain of Responsibility behavior design pattern. The only true implementation of HMVC for PHP that I am aware of is the Claw framework originated on Tigris and abandoned by the author years ago. There are two versions on Tigris--the downloadable version and the version in SVN. The SVN version includes more improvements. As I understand it, the original idea for HMVC was to create an application using a hierarchial structure of MVC triads from a top triad (the application) through any number of intermediate triads and then the lowest level triad (usually a standalone widget in MVC form). The lowest level with the lowest triads in communication with their parent triads using the Publish and Subscribe design pattern (Observer pattern). Events were triggered at the widget level triad (e.g., a button press or other HTML element activity triggered and event which was observed by the ascendent triads).
PAC uses the Mediator behavioral design pattern rather than the Chain of Responsibility pattern. The triad are composed of three agents. The Presentation agent is similar to a View in purpose. The View agent cannot access the Abstraction agent directly where this is allowed in HMVC. The Abstraction agent contains no actual model code and sends requests to a central storage solution which passes the queries through the Control agent enroute to the View. The Control is somewhat similar to a MVC controller but has more responsibilities and those responsibilities are enforced more strictly than MVC.
I do not post much although I visit here a lot, but have been using and learning Yii for about 20 months. Of the frameworks I have used over the past 10+ years, I consider Yii to be the best solution for my needs and for me a far better and elegant solution than PAC, HMVC and other architectural patterns. It should be possible to mimic a true HMVC architecture down to the widget level using any number of nested modules with Yii in combination with the Observer pattern but using Yii IMHO as it was intended is a better, simpler, and more versatile solution. Once you get over the initial learning curve and build a modular application foundation for building projects with reusable modules and portlets, you can use that code as a base for starting new projects and save a lot of time by doing so.
#16
Posted 16 December 2012 - 03:25 PM
samdark, on 14 June 2011 - 03:28 PM, said:
- There are no real advantages over current architecture… well maybe there are for some cases when you need a widget to be self-contained with it's own actions and URLs.
- It will add complexity. A lot of complexity.
- It will possibly slows things down for cascade file system and stuff.
Hi alex,
What you mean here? Did you talk about widget as action provider? like in this wiki:
How to use a Widget as an Action Provider
#17
Posted 17 December 2012 - 04:03 AM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#19
Posted 14 January 2013 - 01:43 AM
This should exist elsewhere for the edification of the masses, as it seems a shame to leave it buried within a forum thread.
mmx, on 23 January 2012 - 03:17 PM, said:
A true implementation of HMVC uses the Chain of Responsibility behavior design pattern. The only true implementation of HMVC for PHP that I am aware of is the Claw framework originated on Tigris and abandoned by the author years ago. There are two versions on Tigris--the downloadable version and the version in SVN. The SVN version includes more improvements. As I understand it, the original idea for HMVC was to create an application using a hierarchial structure of MVC triads from a top triad (the application) through any number of intermediate triads and then the lowest level triad (usually a standalone widget in MVC form). The lowest level with the lowest triads in communication with their parent triads using the Publish and Subscribe design pattern (Observer pattern). Events were triggered at the widget level triad (e.g., a button press or other HTML element activity triggered and event which was observed by the ascendent triads).
PAC uses the Mediator behavioral design pattern rather than the Chain of Responsibility pattern. The triad are composed of three agents. The Presentation agent is similar to a View in purpose. The View agent cannot access the Abstraction agent directly where this is allowed in HMVC. The Abstraction agent contains no actual model code and sends requests to a central storage solution which passes the queries through the Control agent enroute to the View. The Control is somewhat similar to a MVC controller but has more responsibilities and those responsibilities are enforced more strictly than MVC.
I do not post much although I visit here a lot, but have been using and learning Yii for about 20 months. Of the frameworks I have used over the past 10+ years, I consider Yii to be the best solution for my needs and for me a far better and elegant solution than PAC, HMVC and other architectural patterns. It should be possible to mimic a true HMVC architecture down to the widget level using any number of nested modules with Yii in combination with the Observer pattern but using Yii IMHO as it was intended is a better, simpler, and more versatile solution. Once you get over the initial learning curve and build a modular application foundation for building projects with reusable modules and portlets, you can use that code as a base for starting new projects and save a lot of time by doing so.
#20
Posted 20 June 2013 - 04:37 PM
samdark, on 14 June 2011 - 03:28 PM, said:
- There are no real advantages over current architecture… well maybe there are for some cases when you need a widget to be self-contained with it's own actions and URLs.
- It will add complexity. A lot of complexity.
- It will possibly slows things down for cascade file system and stuff.
HMVC doesn't need any connection with cascading file systems. They are two separate things.