Hi Massimo,
Firstly, there is no need to extend the controller class. Assuming your class is named “prv_Gestione” A little cleaner would be to create the file:
custom/modules/prv_Gestione/action_file_map.php
with the contents
<?php
$action_file_map['generaPreventivo'] = 'custom/modules/prv_Gestione/generaPreventivo.php';
Then add your code in the file:
custom/modules/prv_Gestione/generaPreventivo.php
You can access the respective bean in this file by
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
$myGestione = new prv_Gestione;
$myGestione->retrieve($_REQUEST['record']);
To trigger the action, edit the following file (if it doesn’t exist, then create a copy from modules/prv_Gestione/metadata/detailviewdefs.php)
custom/modules/prv_Gestione/metadata/detailviewdefs.php
Add the following code to the bottom of this file, or integrate it in the $viewdefs array:
$viewdefs['prv_Gestione']['DetailView']['templateMeta']['form']['buttons']['GENERA_PREVENTIVO'] = array (
'customCode' => '<input />',
'sugar_html' => array (
'type' => 'submit',
'value' => '{$MOD.LBL_GENERA_PREVENTIVO}',
'htmlOptions' => array (
'class' => 'button',
'id' => 'genera_preventivo_button',
'title' => '{$MOD.LBL_GENERA_PREVENTIVO}',
'onclick' => "window.location='index.php?module=prv_Gestione&action=generaPreventivo&record={$bean->id}'",
'name' => 'genera_preventivo_button'
)
);
Finally, to define the text for the button, create the following file:
custom/Extension/modules/prv_Gestione/Ext/Language/en_us.generapreventivo.php
with the contents
<?php
$mod_strings['LBL_GENERA_PREVENTIVO'] = 'Genera preventivo';
Afterwards, do a Admin -> Repair -> “Quick Repair and Rebuild”