Yii Framework Forum: multiple (loosly coupled) modules building up a common (global) navigation menu - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

multiple (loosly coupled) modules building up a common (global) navigation menu Rate Topic: -----

#1 User is offline   OriginalCopy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 13-March 09

Posted 05 February 2010 - 06:41 PM

After inspecting a little bit Yii's internals (because of this problem), it seems CController::forward()'ing to another module/controller/action from within the application's layout leads to endless recursion, which is pretty understandable.

(But forget about that problem, as ...) However I feel (note the subjectivity here) I'm doing it wrong. I (will) have some loosely coupled modules (which can act as standalone applications) and I want them all to store something in a common place, a variable, a component or something, so that I can have a common navigation menu throughout the site, with all the links generated by each module.

Considering that loose coupling is VERY important to me, what is the best way to achieve that?

Addendum
Sorry, I've forgot to say that there may be loose dependencies among modules. A module may decide, when noticed by another module, to do or not to do (eg to add a link to the global navigation) something. Also note, there may be circular dependencies: module A request module B some info, then A tells back B to add the "feature" or not to the "navbar".

Of course, I'm oversimplifying the problem. It may be anything, not just a "navbar". It may also be a storage for objects for another module, for example an administration panel.

Luckily, circular dependencies won't need more than a full handshake (as in networking terms), that is, there will be at most three calls between two given modules A and B which negociate a feature.
0

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 06 February 2010 - 03:28 AM

To make a common menu you can create a widget (it can also extends CMenu widget) and rewrite it's run() method. This method should walk through all modules and call each module's method generateLinks(), for example. And then just render a menu based on these links (links can be an array, strings or any other type).

In the general case there can be many approaches. You can create a component, an application component, or a module to manage other modules.
0

#3 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 06 February 2010 - 04:43 AM

In general, if you want modules to communicate you need to build an API for each module which provides the functions available to other modules.
So module A (which is defined as "class A extends CModule") could provide the following APIs:
A::generateLinks()
A::getData($itemname)
...
0

#4 User is offline   OriginalCopy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 13-March 09

Posted 06 February 2010 - 02:49 PM

View Postandy_s, on 06 February 2010 - 03:28 AM, said:

To make a common menu you can create a widget (it can also extends CMenu widget) and rewrite it's run() method. This method should walk through all modules and call each module's method generateLinks(), for example. And then just render a menu based on these links (links can be an array, strings or any other type).

In the general case there can be many approaches. You can create a component, an application component, or a module to manage other modules.
I'll go with the "application component" way, because I intend to do it really reusable: the application component will simply store chucks of data. The actual widget will be created by views based on a specific chuck.
0

#5 User is offline   DerekC 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 09-December 09
  • Location:Europe

Posted 15 February 2010 - 12:20 PM

Some time ago (years) I was active on the Horde project(s)... I seem to remember they had a way of declaring a 'provides' section. If you have a common API for all your modules they would register themselves (dynamically or via a config file) into the current application (where an application is made up of modules).

In this way any Module could ask the Application: "Is 'function|service|module' 'present|active|provided'?", and deal with the result - e.g. check for the existance of a certain method, etc.

This would enable you to package any number of modules into an application, and they would simply behave well, and play nicely with other modules in the app.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users