こんにちは、私のカスタム コンポーネントでは、ユーザーが試用期間中かどうかを確認するために、メンバーシップ用の joomla ユーザーのカスタム パラメータを設定する必要があります。これは、特定のユーザーのコンポーネント管理パネルから変更できます。
パラメータの取得中に問題が発生します。Cookieに保存されていて、更新されていないと思います。私はそれをチェックするためにそのようなコードを書きました。
$user = JFactory::getUser(JRequest::getVar('id','0'));
echo $user->getParam('trialPeriod','0');
値を保存するには、JHTML booleanlist を使用しています。
$user->setParam('trialPeriod',$data['trialPeriod']);
$user->save();
次に、そのユーザーの行にある joomla ユーザー テーブルの値を、params の列として格納します。
{"trialPeriod":"0"}
この状況では、値を 0 としてエコーします。次に、trialPeriod var の状態を 1 に変更し、db に格納すると、db が次のように更新されます。
{"trialPeriod":"1"}
結局のところ、値が画面に表示されるページを更新していますが、値はまだ0のままです。
明確にするために;
まず、適切に変更されたパラメータを保存することに問題はありません。問題は、変更されたものを取得することです。関連するコードは次のとおりです。
$user = JFactory::getUser();
$doc = JFactory::getDocument();
if($user->getParam('trialPeriod',0) == 0){
$ed = JFactory::getDate($obj->expirationDate);//obj is user from custom table and there is no problem with getting it.
$isTrialEnd = FALSE;
}else{
$ed = JFactory::getDate($user->getParam('trialExp',0));
$isTrialEnd = TRUE;
}
if($isTrialEnd){
//do something else
}else{
echo $user->getParam('trialPeriod','0');
}
実際にはコードの大部分は説明する必要はありませんが、アイデアは得られます。
これに対する解決策は何ですか?
編集しました。
$app = JFactory::getApplication();
$config = JFactory::getConfig();
$db = $this->getDbo();
$isNew = empty($data['uid']) ? true : false;
$params = JComponentHelper::getParams('com_dratransport');
if($isNew){
// Initialise the table with JUser.
$user = new JUser;
// Prepare the data for the user object.
$username = self::getCreatedUserName($data['type']);
$data['username'] = !empty($data['username']) ? $data['username'] : $username;
$data['password'] = $data['password1'];
$useractivation = $params->get('useractivation');
// Check if the user needs to activate their account.
if (($useractivation == 1) || ($useractivation == 2)) {
$data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword());
$data['block'] = 1;
}
}else{
$user = JFactory::getUser($data['uid']);
$data['password'] = $data['password1'];
}
$membership = DraTransportHelperArrays::membershipCFG();
$membership = $membership[$data['membership']];
if($data['membership'] == 4)
$data['groups'] = array($params->get('new_usertype',2),$params->get($membership,2));
else
$data['groups'] = array($params->get($membership,2));
$data['name'] = $data['companyName'];
$user->setParam('trialPeriod',$data['trialPeriod']);
// Bind the data.
if (!$user->bind($data)) {
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()));
return false;
}
// Load the users plugin group.
JPluginHelper::importPlugin('user');
// Store the data.
if (!$user->save()) {
$app->enqueuemessage($user->getError());
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
return false;
}
このコードは、users テーブルに関連するデータを格納するためのものです。