HOWTO: Creating Custom Controller and View Classes

sugarcrmdevelopers —  February 7, 2011 — 5 Comments

Sugar uses an MVC pattern to handle incoming requests to the application. I won’t delve into all the details on how this works, a better resource for this is Chapter 2 of The Definitive Guide to SugarCRM: Better Business Applications.

That said, one hangup people seem to run into in the forums is naming conventions for the controller and view class. If you are authoring your own module, you should name your controller and view classes like this ( assuming ‘Module’ is the name of the module we are using ):

// controller class for a module
class ModuleController extends SugarController
{
}

// view class for a view that extends a builtin view
class ModuleViewEdit extends ViewEdit
{
}

// view class for a view that is an entirely new view named 'Something'
class ModuleViewSomething extends SugarView
{
}

If you are extending a view or controller off an already existing module, use this naming convention instead:

// controller class for a module that has a controller class defined already
class CustomModuleController extends ModuleController
{
}

// controller class for a module that doesn't have a controller class defined already
class CustomModuleController extends SugarController
{
}

// view class for a view that extends a view already defined in the module
class CustomModuleViewEdit extends ModuleViewEdit
{
}

// view class for a view that extends a builtin view where the class isn't already defined in the module
class CustomModuleViewEdit extends ViewEdit
{
}

// view class for a view that is an entirely new view named 'Something'
class CustomModuleViewSomething extends SugarView
{
}

5 responses to HOWTO: Creating Custom Controller and View Classes

  1. 

    The real hangup is that the “module” is not what it appears to be in the Studio or Module Builder. If you create a package with a Key of “CON” containing a module named NothingImportant, then the module will be CON_NothingImportant.

    If you look closely at the URL parameters you will see this.

  2. 

    Is there a parameter for the package manifest to add new actions without having to use file_exists to check if a stock controller is already in place for a stock module? Something similar to the logic_hooks parameter?

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s