Page 1 of 1

Multimodularized Pages

Posted: Thu Jun 18, 2009 5:32 pm
by kaisellgren
Hello,

I'm currently writing an application that works with modules. The module part is all okay, but I am not entirely clear on what would be the best approach to display multiple modules on a same page. The way common MVC like systems could work is that an URL like "site.com/article/full/18543/how-to-lose-weight" (I'm not implying anything about you :)) -> would launch "article" -module and call its "full" -method with params "18543" and "how-to-lose-weight".

However, I'm writing an application where I need to have multiple modules on the same page. Currently, I let the user to create, delete and modify pages. He has an interface (a GUI) to decide how a page should look like. For example, he can name page "article" and make it to look like a two-column layout where he wants to have a shoutbox on the rightside in a sidebar and articles on the main body (the larger column). Now, how would I go for constructing the URL for something like that? I would like to keep my current page system, but I find it a bit hard to come up with a solution. You see, if the URL would load the "article" module, then the shoutbox wouldn't be loaded. So, I guess the URL is a reference to a DB entry containing the info about which modules to load? That's my current thought. So, after the user has created a page "article" and put two modules into the "article" -page (which is a two-column layout), then the URL "site.com/article/full/18543/how-to-lose-weight" would load the "article" -page, which tells the application the needed modules to load.

This leads me to two questions/problems. First, would the rest of the URL "/full/18543/how-to-lose-weight" go to the "article" -module or to the "shoutbox" -module? How do I determine that? The second problem is if this "shoutbox" -module has a link to register an account rather than posting as an anonymous, where will this link take the user to?

I'm basically trying to figure out a good way to build a relationship between different pages, modules and URLs.

Edit: Currently I have:
Skins that handle the appearence and the possible positions where you can place modules.
Pages that tell which modules are in which "page" and where they are positioned (in a skin).

And now I need to determine the way I work with URLs. Any help is welcome. :)

Re: Multimodularized Pages

Posted: Thu Jun 18, 2009 6:12 pm
by Weirdan
kaisellgren wrote: Currently, I let the user to create, delete and modify pages. He has an interface (a GUI) to decide how a page should look like. For example, he can name page "article" and make it to look like a two-column layout where he wants to have a shoutbox on the rightside in a sidebar and articles on the main body (the larger column). Now, how would I go for constructing the URL for something like that? I would like to keep my current page system, but I find it a bit hard to come up with a solution. You see, if the URL would load the "article" module, then the shoutbox wouldn't be loaded. So, I guess the URL is a reference to a DB entry containing the info about which modules to load? That's my current thought. So, after the user has created a page "article" and put two modules into the "article" -page (which is a two-column layout), then the URL "site.com/article/full/18543/how-to-lose-weight" would load the "article" -page, which tells the application the needed modules to load.
I would make a Page controller and pass request to it. Page would know what 'modules' to load and would pass entire request to them, acting kinda like a front controller. Modules would render themselves to the response object, and page controller would place their output into appropriate slots in its view:

Code: Select all

 
// controller
class PageController extends Zend_Controller_Action {
     public function indexAction() {
         foreach ($this->getModules() as $module) {
              $module->processRequest($this->request, $this->response);
              $this->view->{$module->getSlotName()} = $this->response[$module->getSlotName()];
         }
         $this->render($this->getPageViewScript());
     }
     protected function getModules() {
         // assuming we're using Propel
         return ModulePeer::findByPageName($this->request->getParam('page', 'index'));
     }
     protected function getPageViewScript() {
         $page = PagePeer::findByName($this->request->getParam('page', 'index'));
         return $page->getViewScript();
     }
}
// one of view scripts
<div class="page blogpost">
   <div class="blog post">
   <?=$this->post?>
   </div>
   <div class="blog comments">
   <?=$this->comments?>
   </div>
</div>
 
urls would look something like this:
/page/blog/article/how-to-grow-your-bank-account/comments-page/10
to show 'How to grow your bank account' article with 10th comment page in 'blog' page layout.

Re: Multimodularized Pages

Posted: Thu Jun 18, 2009 6:30 pm
by Christopher
I am not sure what the problem actually is. And I think the term is partial, not module. It seems like "18543" should get you to all the information you need. You shouldn't need any more than that to generate a layout.

Re: Multimodularized Pages

Posted: Thu Jun 18, 2009 6:41 pm
by kaisellgren
@Weirdan: It would probably be something like that. I'm wondering, if I have a "module" that contains a link "register new account", where does this link take you to? Would it just take you to /article/register/... because the /article essentially loaded the current page? This also leads to the other problem,
Weirdan wrote:and would pass entire request to them
the "them" is the problem. If all "modules" on the page receive the whole query, there could be some conflicts. What if the query has a word "comment", wouldn't it be used by many modules like a Comment Form, Shoutbox, etc?

Maybe I'm just looking into the wrong direction and there is an easier way to implement all this. Ugh, I have a headache, I think I have a summer flu.

I'll have a deep look into your code tomorrow.
It seems like "18543" should get you to all the information you need.
The "18543" maybe tells the article module to load the corresponding article, but what it may tell other modules? Imagine having two modules "downloads" and "image gallery" on the same page. Now if you have an URL /view/1234/ what will it do? Show an image that corresponds to "1234" or download the corresponding file? That's pretty much the problem. I need a relationship between pages, modules and URLs.

Re: Multimodularized Pages

Posted: Thu Jun 18, 2009 7:10 pm
by alex.barylski
I am not sure what the problem actually is. And I think the term is partial, not module.
In CMS parlance, module is commonly used to describe pluggable units of funcitonality that usually act as mini-applications, in that they have a controller, model and view. I hate that name personally (module is such a catch all term) but it's most common, second maybe only to component.
The "18543" maybe tells the article module to load the corresponding article, but what it may tell other modules? Imagine having two modules "downloads" and "image gallery" on the same page. Now if you have an URL /view/1234/ what will it do? Show an image that corresponds to "1234" or download the corresponding file? That's pretty much the problem. I need a relationship between pages, modules and URLs.
It is generally accepted that only a single module can maintain state via URI propagation. This is why many CMS make a distinction between module and component, to mean different things.

Re: Multimodularized Pages

Posted: Thu Jun 18, 2009 11:30 pm
by Christopher
kaisellgren wrote:The "18543" maybe tells the article module to load the corresponding article, but what it may tell other modules? Imagine having two modules "downloads" and "image gallery" on the same page. Now if you have an URL /view/1234/ what will it do? Show an image that corresponds to "1234" or download the corresponding file? That's pretty much the problem. I need a relationship between pages, modules and URLs.
But your URL was "site.com/article/full/18543/". That means you know that is "an article", "a full article" and "article 18543". So you could associate "modules" with "articles", with "full articles" and with specific articles. Sounds like more a layout problem.

Re: Multimodularized Pages

Posted: Fri Jun 19, 2009 3:07 am
by Weirdan
kaisellgren wrote:
Weirdan wrote:and would pass entire request to them
the "them" is the problem. If all "modules" on the page receive the whole query, there could be some conflicts. What if the query has a word "comment", wouldn't it be used by many modules like a Comment Form, Shoutbox, etc?
If you're afraid of naming conflicts you could throw away url simplicity and get creative with parameter naming scheme, something like /page/blog?comment[page]=10&shoutbox[page]=3

Re: Multimodularized Pages

Posted: Fri Jun 19, 2009 6:07 am
by kaisellgren
PCSpectra wrote:In CMS parlance, module is commonly used to describe pluggable units of funcitonality that usually act as mini-applications, in that they have a controller, model and view. I hate that name personally (module is such a catch all term) but it's most common, second maybe only to component.
I have been thinking about just that, having modules and components, but I have to still plan my strategy and design. Do both components and modules use MVC in general? At the moment I have modules only which use MVC, but I've been thinking about having components, too.

I'm not familiar with terms, especially with English terms. Is a component sort of a big application in a single URL whereas modules are tiny apps that can be displayed on a page along with other modules and content?
Weirdan wrote:get creative with parameter naming scheme
Hmm, yeah, that's one good idea. I could play around and create a meaningful yet intuitive URL scheme. Thanks.

Re: Multimodularized Pages

Posted: Fri Jun 19, 2009 7:58 am
by alex.barylski
Do both components and modules use MVC in general? At the moment I have modules only which use MVC, but I've been thinking about having components, too.
Some do, most don't. A full scale componentized architecture is extremely challenging, I've been working on my own CMS for close to a decade, with a component system similar to VB programming was always the goal -- I'm getting very close now but it's still not easy so I know something is wrong with the design or I still do not fully understand everything.

modules and components are typically the same thing, except in Joomla, where the distinction lies in the fact that modules are rendered post two step view, and rely *usually* on internal data to present state, not URI and not user configurable --- at least not using SEF/SEO/URI.
I'm not familiar with terms, especially with English terms. Is a component sort of a big application in a single URL whereas modules are tiny apps that can be displayed on a page along with other modules and content?
That would be the gist of the idea usually -- again there are not formal definitions that I know of but it's more common for CMS' to follow the lead of Joomla than most other CMS. Joomla has some serious architectural issues and a horrible security track record, but compared to others, they do it best, relatively speaking.

Cheers,
Alex

Re: Multimodularized Pages

Posted: Thu Jun 25, 2009 7:58 am
by kaisellgren
PCSpectra wrote:in Joomla, where the distinction lies in the fact that modules are rendered post two step view, and rely *usually* on internal data to present state, not URI and not user configurable --- at least not using SEF/SEO/URI.
In Joomla, does the URI not affect modules? Also, what do you mean by modules being rendered post two step view?

Re: Multimodularized Pages

Posted: Sun Jun 28, 2009 1:00 am
by silenceghost
I don't know the proper way of doing it but
I've created global variable $GLOBALS['LOADER_DIR'] and make include of that module
i've done like this

Code: Select all

 
class Zend_Loader
{
 public static function loadClass($class)
    {
        if (class_exists($class, false) || interface_exists($class, false)) {
            return;
        }
        $required_module_file = ROOT_PATH . DIRECTORY_SEPARATOR.$GLOBALS['LOADER_DIR'].DIRECTORY_SEPARATOR. $file;
 if(file_exists($required_module_file))
            $file =  $required_module_file;
 
     include_once($file);
   if (!class_exists($class, false) && !interface_exists($class, false)) {
            throw new Exception("File \"$file\" does not exist or class \"$class\" was not found in the file");
        }
}
}
 
In the controller Section i've done

Code: Select all

 
function test(){
   $GLOBALS['LOADER_DIR'] = MODULE_DIRECTORY.'/CustomModule';
   $CustomModule        = new CustomModuleController(); 
   $CustomModule->customFunca();
 $CustomModule->customFuncb();
  $GLOBALS['LOADER_DIR'] = MODULE_DIRECTORY.'/CustomModulea';
   $CustomModulea       = new CustomModuleaController();    
  $CustomModulea->customFunca();
  $CustomModulea->customFuncb();
 
  $this->model->functiona();
  $this->model->functionb();
}