Pages

Sunday, April 21, 2013

Social Engine 4-Creating a widget in a module

Before creating a widget in a module we need to register the same

1. Go to your module folder and then in your module go to file

settings/content.php

This file contains all widgets which this module will provide.

As an example we will create a widget to show graph and also called it graph

This file returns an array of array's where the former contains various widgets information

 return array(  
  array(  
   'title' => 'Navigation Tabs',  
   'description' => 'Displays the Navigation tabs(menu) for Credits: Credits Home, My Credits, FAQ. Put this widget on the top of Credits Home and My Credits pages.',  
   'category' => 'Credits',  
   'active' => true,  
   'type' => 'widget',  
   'name' => 'credit.navigation-tabs',  
  ),  
  array(  
   'title' => 'Top Members',  
   'description' => 'Displays top members list with highest number of credits. Put this widget on Credits Home or on any other page.',  
   'category' => 'Credits',  
   'active' => true,  
   'type' => 'widget',  
   'name' => 'credit.browse-users',  
   'defaultParams' => array(  
    'title' => 'Top Members'  
   )  
  ),  
  array(  
   'title' => 'Graph',  
   'description' => 'Displays a widgets which displays a list of quick links to create a graph.',  
   'category' => 'Credits',  
   'type' => 'widget',  
   'name' => 'credit.graph',  
    'active' => true,  
   'defaultParams' => array(  
    'title' => 'Graph'  
   )  
  ));  

Look in the last array we have added our custom widget array in the end

Now lets move into the widget's folder of our module

Let's suppose our Module name is "Credit"

so in /widgets/graph/controller.php

We need to create these directories as per requirement

1:  Class Credit_Widget_GraphController extends Engine_Content_Widget_Abstract  
2:  {  
3:     public function indexAction()  
4:     {  
5:        $this->view->myvar="myvarvalue";  
6:       //You can also include forms (defined in forms of your module)  
7:         $this->view->form=new Filter_Form()  
8:     }  
9:  }  

Look at the name of the class see in settings file we have defined property "name" in widget array as credit.graph like wise here "Credit" is our module and "Graph" is widget...This should match with property.

Next we define template in
in /widgets/graph/index.tpl

and Access variables as

1:  <?php echo $this->filterForm ?>  


That's It Add widget from backend to the respective page

No comments:

Post a Comment