0
我想用自定義的註冊表單(fabrik的juser插件)在joomla中創建新的用戶組,並將用戶分配給該組(這部分是錯過的,真的不知道如何添加它)。 我寫了一些包含在表單的php插件中的腳本。但不知道錯誤在哪裏。 獲取一些信息在哪裏出錯是有幫助的。在joomla用戶註冊時創建用戶組
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Insert columns.
$columns = array('parentid','lft','rgt','title');
$title = '{user_registration_form___companyid}';
$child_query1 = "SELECT max('id') FROM '#__usergroups'";
$newgroupid = $child_query1+1;
$parent_id = '2';
$db->setQuery($child_query);
$max_rgt = $db->loadResult();
// calculate left and rgt for new entry
$new_lft = $max_rgt;
$new_rgt = $max_rgt + 1;
// update lft and rgt of all entries having lft , rgt greater than max_rgt
$upd1 = "UPDATE '#__usergroups' SET 'lft' = 'lft' + 2 WHERE 'lft' >= " $max_rgt;
$upd2 = "UPDATE '#__usergroups' SET 'rgt' = 'rgt' + 2 WHERE 'rgt' >= " $max_rgt;
// Insert values.
$values = array($parent_id, $new_lft, $new_rgt, $title);
// Prepare the insert query.
$query
->insert($db->quoteName('usergroups'))
->columns($db->quoteName($columns))
->values(implode(',', $db->quote($values)));
// Reset the query using our newly populated query object.
$db->setQuery($query);
try {
// Execute the query
$result = $db->execute();
//use $db->query() in Joomla2.5
} catch (Exception $e) {
// catch any database errors.
}
$newid = (int)$db->insertid(); //get new record id