Saturday, July 14, 2012

The Complete Guide to Social Engine 4 Module Development Part 1: Development Set Up, Tools and the SDK

In this multi-part post, I will teach you how to create a social engine module. I'll try touch every bells and whistles of SE4 module development. Since I'm lacking  ideas for introductory statements let's get started.

We will be creating a car module. The module will enable users to create cars. Cars will have a profile page, can be liked, can be commented on, has a profile photo, can have albums if the album module is available and can have videos if the video module is available. The module will also provide a number of car related widgets.

Begin by installing creating a local development site of SE4 (this guide will refer to it as localhost) and adding the album and video modules.  Now go to Admin > Manage > Packages & Plugins > Developer SDK > Create a Package. Select "module" as type and set "car" as the module name. Fill out the other fields as you see fit.


Please note that even though the field description of the name field says "Lowercase, alphanumeric, and hyphens ("-") only" it is not advisable to use hyphens in the module name if the module will be using widgets. Let us take for example that we decided to use "my-car" as the module name. This means the modules resources will be prefixed with MyCar_. Models will be, MyCar_Model_, forms will be MyCar_Form, controllers wil be MyCar_...Controller etc. Also the module will reside in the path application/modules/MyCar/. The problem will be the with widgets. They will be under application/modules/MyCar/widgets and the classes will be prefixed with MyCar_Widget_. SE4 will not be able to load widgets that are prefixed with camel cased module names (camel casing is caused by the hyphen). You may try to load a widget using my-car.widgetname for example but this will not work since SE4 will try to look for it in application/modules/Mycar instead of application/modules/MyCar. This could be a bug. To avoid it simply avoid the use hyphens in the module's name.

Create the module download it, and install it in the development site. Put the site in development mode. It's advisable to use firefox with firebug and firephp during development as a number of development logs appear in the firebug console when SE4 is in development mode.

Now point the browser to /car. If you can see the default page for the car module that means you are good to go to the next step.

2 comments:

  1. You may try to load a widget using my-car.widgetname for example but this will not work since SE4 will try to look for it in application/modules/Mycar instead of application/modules/MyCar. This could be a bug. To avoid it simply avoid the use hyphens in the module's name.

    // This is odd. I just have such a problem and solution was use lowercase category (=directory) name instead of a model name. For example: module - 'my-module', widget - 'my-widget', widget category - 'MyModule' (and module directory), widget name - 'mymodule.my-widget'. Load widget using 'mymodule.my-widget' does work just fine

    ReplyDelete
  2. It think you must have renamed the module dir. From the SDK generating a module named "my-module" generates the directory application/modules/MyModule. Specifying the name "mymodule.my-widget" will cause SE4 to search for application/modules/Mymodule/widgets/my-widget/. The correct way to specify the name is of course "my-module.my-widget" but because of the bug SE4 ignores the hypen and uses "Mymodule" instead. Your widget resolves properly only if MyModule has been renamed to Mymodule. That will work for your widgets but will ruin the resolution of other resources. Note that the widget's category (specified in content.php) doesn't have anything to do with the name/directory resolution.

    ReplyDelete