Creating custom view for SugarCRM module

sugarcrmdevelopers —  December 23, 2011

Hello everyone, i guess for most of us is another day at work :)

Today i want to share with you all, how you can create a custom view for any of your modules. You can use this view to integrate some script or anything inside sugar and it will look like it comes from there. So lets get started :)

lets imagine we have created a module semi_Metadata, and we want to add a new view and menu button called administer metadatas inside it.

If you look at the picture you will see that we have a new link in the menu called Administer metadata, and with it we don’t want to show editview,detailview or listview. We want to show our custom view. To create a link we will add this code to the Menu.php inside our semi_Metadatas module.

if(ACLController::checkAccess('semi_Metadatas', 'edit', true)) $module_menu[]=Array(
"index.php?module=semi_Metadatas&action=semi_AdministerMetadata", "Administer metadata",

To make this link do anything, we will need to map an view to the action we created. If you look closely to the code we added you will see we created a link to action semi_AdministerMetadata.

For now our module doesn’t know what to do when that action is called. To teach him that, we need to create a file if it doesn’t exist called controller.php inside our module directory. We add the following code to it:

if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class semi_MetadatasController extends SugarController {

	function action_semi_AdministerMetadata() {
		$this->view = 'semi_administermetadata';


Here we are saying that if we ever get a request for action named semi_AdministerMetadata we will load a view demi_administermetadata. Note we added action_ to function name. The view file is located inside the module/views directory. We will now create our view and call it view.semi_administermetadata.php with the code:

if (!defined('sugarEntry') || !sugarEntry)
	die('Not A Valid Entry Point');


class semi_MetadatasViewSemi_AdministerMetadata extends SugarView {
	 * Constructor

	public function __construct() {
	 * display the form

	public function display() {

		include ('test.php');

		//echo "a";

When creating a view we are extending a SugarView class and out primary function is desplay(). What ever we do or echo here it will be shown inside the sugarcrm. For a test i have included a simple test.php file that will just show a form for us like a demonstration. Take a look at the picture below:

I hope you enjoyed reading about this and that you will join me on forums to talk more about development and business :)

Talk more on this on forum :