如何在自定义入口点中使用Sugarcrm\Sugarcrm\Util\Uuid::uuid1()?
我正在学习SuiteRM。我需要使用来自自定义入口点的特定id创建一个新bean,当我尝试此代码时,生成该id是无效的如何在自定义入口点中使用Sugarcrm\Sugarcrm\Util\Uuid::uuid1()?,sugarcrm,suitecrm,Sugarcrm,Suitecrm,我正在学习SuiteRM。我需要使用来自自定义入口点的特定id创建一个新bean,当我尝试此代码时,生成该id是无效的 // Create bean $testAccountBean = BeanFactory::newBean('Accounts'); // Set the new flag $testAccountBean->new_with_id = true; $id = Sugarcrm\Sugarcrm\Util\Uuid::uuid1(); $testAccountBe
// Create bean
$testAccountBean = BeanFactory::newBean('Accounts');
// Set the new flag
$testAccountBean->new_with_id = true;
$id = Sugarcrm\Sugarcrm\Util\Uuid::uuid1();
$testAccountBean->id = $id;
$testAccountBean->name = generateRandomString();
$testAccountBeanId = $testAccountBean->save();
echo $testAccountBeanId;
我什么也得不到
当我检查调用Sugarcrm\Sugarcrm\Util\Uuid::uuid1()
的结果时,没有任何结果
感谢您的任何想法该函数名为create_guid,需要
include/utils.php
,您就可以调用它了
<?php
if (!defined('sugarEntry')) {
define('sugarEntry', true);
}
require_once 'data/BeanFactory.php';
require_once 'include/utils.php';
$testAccountBean = BeanFactory::newBean('Accounts');
$id = create_guid();
您需要以以下方式调用它:
$testAccountBean->new_with_id = true;
$testAccountBean->id = create_guid();
请注意,如果您使用create_guid函数分配了自己的ID,那么还需要设置“new_with_ID”。您可以在以下路径找到函数:include\utils.php
以下是职能机构:
function create_guid()
{
$microTime = microtime();
list($a_dec, $a_sec) = explode(' ', $microTime);
$dec_hex = dechex($a_dec * 1000000);
$sec_hex = dechex($a_sec);
ensure_length($dec_hex, 5);
ensure_length($sec_hex, 6);
$guid = '';
$guid .= $dec_hex;
$guid .= create_guid_section(3);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= $sec_hex;
$guid .= create_guid_section(6);
return $guid;
}
感谢您的回答和对使用$testAccountBean->new\u时的上下文的澄清,其中\u id=true代码>