SuiteCRM is fast growing open source now a days which is written in PHP a powerful open source language widely used over the web. SuiteCRM development can be much better and robust if follow standards. This can be download and setup on local or live server by download from official website or can be access from github
Before discuss in detail I would like to discuss on a very important part of SuiteCRM i.e. caching. Normally when you make change related to display view it doesn’t reflect same time and need to clear cache by repair. To repair suitecrm you need to visit admin page. Another option available during development in admin setting and it is developer mode. This mode disable caching and you dont need to repair after every modification, but this can put extra load on your CRM.
Important settings in SuiteCRM Development
There are 3 main setting which are most important on live server after setup your CRM
– Developer mode
If developer mode is on then it create some extra load to server because it off the data display from cache. So on production we should off the developer mode.
– Log Level
By default log level is set to fatal. Other available options of log level into suiteCRM are info & debug. Fatal is good for production server.
– Display error and error reporting
You’ll also need to turn off display errors on production server. SuiteCRM have lot of notices and warnings, so to hide these display_errors should be off.
Beans in SuiteCRM
SuiteCRM development follow MVC (Model View Controller) architecture and Beans work as model. In bean we can retrieve data from the database as objects and use for updating records. SuiteCRM comes with BeanFactory which allow loading bean instances or creating new records. Below code can be use to create new bean
$mybean = BeanFactory::newBean('<ModuleName>'); //Here is an example based on above structure: $leadBean = BeanFactory::newBean('Leads'); //Retrieve bean from an existing record $leadBean = BeanFactory::getBean('Leads', $leadId);
In SuiteCRM development, bean has a method get_list. This method allows search and find a list of matching result with pagination. Below is example of get_list.
$beanList = $accountBean->get_list( //Order by the accounts name 'name', //Only accounts with industry 'Media' "accounts.industry = 'Media'", //Start with the 1st record (third page) 0, //No limit - will default to max page size -1, );
get_list method is very useful if you need data with pagination. Another important method is available which return data without pagination. This method is get_full_list. Below is example.
$beanList = $accountBean->get_full_list( //Order by the accounts name 'name', //Only accounts with industry 'Media' "accounts.industry = 'Media'" );
Sometimes you want to retrieve single record and you have no id of that record. SuiteCRM comes with a bean method retrieve_by_string_fields. This method allows you to get single record based on given field value.
$beanList = $accountBean->retrieve_by_string_fields( array( 'name' => 'EFB Technology', 'account_type' => 'Customer' ) );
There can many other beans which are related to current bean. get_linked_beans allows you get all related beans. In our case we are getting related contacts of account bean
$accountBean->get_linked_beans( 'contacts', 'Contacts', array(), 0, 10, 0, "contacts.primary_address_country = 'India'" );
There are other ways to get related records in suitecrm development. Here is example
//Load relationship $accountBean->load_relationship('contacts'); $contactIds = $accountBean->contacts->get();
Add new record to relationship
SuiteCRM has add method which allows to add new record to a relationship
//Load the relationship $accountBean->load_relationship('contacts'); //Create a new demo contact $contactBean = BeanFactory::newBean('Contacts'); $contactBean->first_name = 'EFB'; $contactBean->last_name = 'Technology'; $contactBean->save(); //Link the bean to $accountBean $accountBean->contacts->add($contactBean);
Delete record to relationship
//Load the relationship $accountBean->load_relationship('contacts'); $contactBean = BeanFactory::getBean('Contacts', $contactId); $accountBean->contacts->delete($accountBean->id, $contactBean);
Thus we have seen there are many in built methods are available for suitecrm development which not only saves time but allow a standard coding practice which reduce chance of bugs and system become more robust.