Skip navigation

Since Social Engine uses the Zend Framework, the files structure are most probably the same. Social Engine uses modules. So inside the application directory you find modules folder. Each module has a separate folder, containing its associated controllers, models, views, widgets ..etc.


Controllers are found inside controllers folder. Each controller class has defined actions (methods) and each method must have an associated view.

Controllers’ naming convention is NameController.php. The controller’s class name becomes {modulename}_{controllername}Controller

So if we’re inside User module and looking at the Profile Controller, you’ll find:

  • Controller filename is ProfileController.php
  • Controller class name is User_ProfileController

The standard method in controller is the init()  method. This is the method that get invoked when the class is instantiated. So inside it important variables that are used within other method in the controller should be set. For example, setting the subject. I understood that socialengine uses the term “Subject” to name a variable, or an item that the user is currently looking at. For example when you view someone’s profile, the subject becomes that person. If you’re viewing a group, subject becomes that group. Subject is set in the init function so as to be available easily to all other methods in the same controller.

To set subject:

if( !Engine_Api::_()->core()->hasSubject() )    {  //Check is there is  no already set subject

$subject_temp = Engine_Api::_()->user()->getUser($id);      //set temp variable to some user, we got using his id

if( $subject_temp->getIdentity() )        {        //If temp is indeed a valid  user

Engine_Api::_()->core()->setSubject($subject_temp);      // set the subject to that user



To get subject:

$subject = Engine_Api::_()->core()->getSubject();

Methods other than init() are called actions. The take the following convention:

public function methodnameAction(){ }

inside which the action’s logic is defined.

Each  controller has a folder containing it’s views, found in views/scripts folder. For Profile Controller explained above, there is a folder called “profile“, and for each method in this controller -other than init() – there must be an associated view. So if we have a method called helloAction, there must be a file called hello.tpl within that folder.

To invoke a certain action within a certain controller, you follow this scheme in URL:


This action gets invoked, and automatically the associated view gets rendered for display.



  1. thank you very much for this post.

    I noticed that ProfileController.php defines two methods, init() and IndexAction(), and so a single index action.

    for each action there is a view that is index.tpl.

    But in my SE4 installation under User/views/scripts/profile I have many .tpl files (8 files: activity.tpl, fields.tpl, and so on)

    When are these views used by the ProfileController ?

    thank you very much

    • Hey, you can actually create views that are not associated with a certain action (like several views for same action). Then within an action you can tell it not to render its default view (indexAction by default renders index.tpl), but to render some different view.

      inside an action:
      return $this->render(‘someView’); //without .tpl extension

      It will then look for “someView.tpl” inside the views folder, instead of the default view.

      However in the case of those views you mentioned, I can’t seem to find out for which controller these views are rendered. I think they are left outs from a draft or so. I tried removing them and nothing funny happened in SocialEngine. Actually I think these files were created, then they decided they should be moved to other Widgets/Views.

      • I got this answer on the SocialEngine Base forum which supports your speculations:

        I think these were converted to widgets and left by mistake, or they both serve the same purpose for some reason.

        For example, look at application/modules/User/views/scripts/profile/info.tpl, then look at application/modules/User/widgets/profile-info/index.tpl. The code is slightly different, but the content is almost exactly the same.

  2. @lucianoenrico great! thanks a lot for the confirmation

  3. Hi,
    how can I call a widget in my custom controller (not a Layout Manager created page)

    thank you

    • I’m not sure if it’s possible, Why not use a “view” instead of widget? I’ll let you know if I find out something. Sorry for the late reply

    • Locianoenrico, Check out this update: you’ll find how to call the widget from a view at very bottom of it.

      • I found the same answer. I was going to write it here but someone was faster than me! 🙂

  4. Thank you for writing these tutorials. They certainly help. I’m trying to figure out how to create a module for my SE4 instance, but I’m having trouble finding information. The SDK in the admin only provides a basic MVC framework with no clues in it and the technical overview contains no information about common calls to the core, but simply an explanation of what each folder is for. Building a plugin for SE is the best kept secret in the social networking world. How do these third party devs figure it out short of decompiling the SE code and going through it line by line. I’m a pretty good developer and I enjoy making plugins for open source projects but it’s like trying to conduct a symphony when all you’ve been given is a music stand and a little stick to wave at the musicians, but no sheet music.

    What am I missing?

    • I am in the same boat with you looking for information about how to customize a plugin but don’t have information enough.

      Have you got any exp in Jobs plugin from Radcodes?

      I am just looking to customize it and hasn’t got any information about it.

      Doing as given in this tutorial but still its not working.

      any ideas?

  5. Thank you for these tutorials. They are very helpful!

  6. I have a website and within it, Social Engine 4.1.4 is just a sub-module. I am using the login system of Social Engine in my website. WHen a user logins and then comes back to the site homepage, I want to show his login status. I mean, that if the user is logged in SE4, then I should greet him with his name. How can I do the same.

  7. Hi ,

    can i call a Controller action inside the controller of my widget

  8. Hi,

    Thanks for this useful tutorial.

    I want to customize the existing module for Jobs by adding some credits in job packages so that user can buy job package and then can consume a credit for every single job post.

    I don’t know how can I add Buy package Action in Packages controller.

    Can someone please put me in some direction or some tutorial or any help?


  9. Thank you very much for this useful post.

3 Trackbacks/Pingbacks

  1. […] Just Another Developer's Blog Just another weblog « Social Engine 4: Controllers […]

  2. […] here is just an iframe, displaying a view as a result of calling a specific action in a controller (see Controllers).  Let’s examine what happens when you try to delete an […]

  3. […] Creating a Controller […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: