Ideas for an extension installer.

Here is the scenario:

In the theme layouts, i want to define certain regions where i want to inject extensions(well, widgets matter a fact).

So let’s assume i would have 4 regions into a layout top/right/bottom/left, smth like:




<div class="top"> [Inject extesions for TOP here] </div>

<div class="main">

   <div class="left">[Inject extesions for LEFT here]</div>

   <div class="content"> [Inject content here] </div>

   <div class="right">[Inject extesions for RIGHT here]</div>

</div>

<div class="top"> [Inject extesions for BOTTOM here] </div>



Now, for each of my regions, i would call a "master" widget which would do a database lookup, more or less like:




<div class="top"><?php $this->widget('CmsWidget',array('region'=>'top')); ?></div>

<div class="main">

   <div class="left"><?php $this->widget('CmsWidget',array('region'=>'left'));?></div>

   <div class="content"> [Inject content here] </div>

   <div class="right"><?php $this->widget('CmsWidget',array('region'=>'right'));?></div>

</div>

<div class="top"><?php $this->widget('CmsWidget',array('region'=>'bottom'));?></div>



The CmsWidget, would look into database and get the widgets for that region and render them into a view, so it would be smth like:




<?php

class CmsWidget extends CWidget{


   public $region;

   

   public function run()

   {

       $widgets=$this->getRegionWidgets($this->region);

       $this->render('widgetsList',array('widgets'=>$widgets));

   }


   private function getRegionWidgets($region='')

   {

       [RUN SQL QUERY and return widget objects  by their sort_order if they are enabled.] 

   }


}



And in the view file of the master widget, it will be like:




<?php 

 foreach($widgets AS $widget)

 {

   $this->widget($widget->full_path,@unserialize($widget->params));

 }

?>



The database structure would be simple enough:




 - widget_id 

 - region (top/left/right/bottom)

 - full_path

 - name

 - description

 - params 

 - sort_order (int defaults to 0)

 - status (enum enabled/disabled)



This would offer a way into admin panel to enable/disable the extensions/widgets easily.

Now, the install part of the widget.

I was thinking, when a widget is added, it will be zip archived, so all that the install process does, is to unzip it, move it to the /extensions folder (into it’s own folder of course) and add a new record in the database.

Now, because the extension might have some configuration params(ie:name/description/ etc), i was thinking to allow a configuration file into the widget so that i can read it before i save the widget into database.

The configuration file would just return an array of default values, like:




<?php

return array(

   'name'   => 'Multi Level Menu',

   'description'=>'Some description here to be shown into database',

   'region'=>'left',

   'status'=>'disabled',

   'params'=>array(

      //extra params here, which will be serialized and passed when the extension is initialized by the master widget. Also, these params will be saved into database and the admin can change them accordingly.

   ),

);



So i have a way to automatically install the widgets and also to manage them as i want to.

P.S: i am also thinking to add a param to decide for what pages this widget should be shown.

Any thoughts regarding this ?

Bright ideas that would extend my initial idea ?

Oh come on, don’t be shy :D

Can be done with http://www.yiiframework.com/doc/api/1.1/CBaseController/#beginClip-detail

There’s also some ideas here:

eazyii-template-system/

How about let them be specialized modules instead of merely extensions?

Then you can do something similar to what the CakePHP powered CMS entitle Croogo does.

A yaml configuration file in the root of the plugin directory is parsed with version number, author, dependencies (if any) and a small screen shot (optional) - you could take a peek at that code if you like.

Nothing is added to the database, unless you enable the plugin - it’s deriving from a generalized class - check this out:

http://www.croogo.or…elopers/plugins

In essence: they have their own boostrap, routes and initialization callbacks.

It’s simple enough I think - even though it’s based on CakePHP.

Should at least give you some additional ideas. :)

I am not sure, but maybe Phundament2 uses a similar approach?

Thanks for the links, i will take a look for sure and see how it is done.

I made some research on my own a few days ago, and came up with this so far (as you suggested, i am not limited to only widgets anymore) :

Like Yii says, an extension can be a widget/module/controller/etc. As long as it extends the Yii/CMS default functionality it is an extension.

Now, for each type of extension, there must be a way to install/enable/delete it(i believe here is the part where i go and read the documentation you’ve sent).

Each type of extension, will have it’s configuration file ( i really want to keep this idea).

The configuration file can be yaml or whatever, didn’t decided yet, but i will keep it very very simple .

Now, when the extension is added, the system becomes aware of it, (let’s say if it exists but it is not in database or it is in db but disabled, means that is installed but not enabled ?) and it could be enabled/disabled from admin panel.

Anyway, i started this on my own but is far from being done as i don’t have time only for this, but when i’ll have something worth looking at, i will let you know .

Just for cross-referencing:

7839-modular-application-skeleton-on-top-of-yii/

;)