Answer the question
In order to leave comments, you need to log in
Why is the date value erased on transfer?
Hello. In the code below, when the button is clicked, the date_subscription_end value should be updated. But, as a result, date_subscription takes a null value (stored in the database in int format). Having set new values, I checked at each stage why this is so, and it turned out that when saving, it erases the date, why is this possible?
public function actionSubscription(){
$jd = Yii::$app->request->post();
$jd = (object)$jd;
Yii::$app->user->setIdentity(\common\models\User::findOne(['id'=>$jd->data]));
$userSettings = UserSettings::findOne(["user_id" => $jd->data]);
if ($userSettings->subscription == 1){
$userSettings->subscription = 0;
echo "date_subscription:".$userSettings->date_subscription."\n";
echo "date_subscription_end:".$userSettings->date_subscription_end."\n";
} else {
$userSettings->subscription = 1;
// $userSettings->date_subscription = date('Y-m-01');
echo "date_subscription:".$userSettings->date_subscription."\n";
$userSettings->date_subscription_end=date('Y-m-d', strtotime('+3 month'));
echo "date_subscription:".$userSettings->date_subscription."\n";
echo "date_subscription_end:".$userSettings->date_subscription_end."\n";
}
if ($userSettings->save()){
echo ".$userSettings->date_subscription." user_id: ".$userSettings->user_id." use_smart_publish: ".$userSettings->subscription. " date_subscription:".$userSettings->date_subscription;
}
$(document).ready(function(){
$(".user_subscription").click(function(){
if (confirm ("Продлить подписку?")) {
jQuery.ajax({
url: '/admin/clients/subscription',
type: 'post',
contentType: 'application/x-www-form-urlencoded',
async: true,
dataType: 'html',
data: {
data: this.name
},
success: function (data) {
alert(data);
},
error: function () {
alert("Error");
location.reload();
}
});
}
});
});
Answer the question
In order to leave comments, you need to log in
KevinSmash , in beforeValidate, look carefully... strtotime is called in the same place.
You
need to know that when save is called, other functions are also
called .
)->beforeSave()->save()->afterSave()
And when we set save(false) then
beforeSave()->save()->afterSave()
Read the Yii2 documentation, so you can talk for a very long time
Are you from one incubator today?
How to pass the value of one date to another?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question