1

Here i need to insert data record automatically in Database using Yii2 when the condition met

i have two table claim and pending

In claim table i have 10 fields including i have another field called turnaroundtime here i will set a date

if the claim table doesn't update on or before the turnaroundtime, then some data from the claim table have to move to another table called pending.

How can i achieve this using Yii 2 Framework

Note: In claim table i also have created_at and updated_at fields also

2 Answers 2

2

you should set a cronjob to run on certain interval of time to invoke some php code that would check the difference between current time, turnaroundtime and updated_at time and move the data to pending table if the condition is met

if((current-time >= turnaroundtime) && (updated_at > turnaroundtime)){
    //move data to pending table
}
Sign up to request clarification or add additional context in comments.

3 Comments

thank you very much its working , how can i everytime run cmd prompt
You need to set cron job working an interval time. If it's unix server, run crontab -e to set the cron job.
docs.phplist.com/CronJobExamples.html. thesitewizard.com/general/set-cron-job.shtml. cronjobs are provided by webservers. If cronjobs are enabled in cpanel you can see it under Advanced tab. If you like this answer please don't forget to upvote my answer !!
1

in Yii2 yii\db\BaseActiveRecord you can use this beforeSave event.

This method is called at the beginning of inserting or updating a record.

public function beforeSave($insert)
{
    if($insert) { 
        // If data is new
        $this->created_at = date("Y-m-d H:i:s");
    } else { 
        //It's updating
        $this->updated_at = date("Y-m-d H:i:s"); 
    }

    //Make sure you return true because it's an event
    return true;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.