Jump to content

Cannot set current time to datetime field


Alpine418
 Share

Recommended Posts

Hi guys,

the field "redirect_last" of type DateTime got not updated. The update on the field "redirect_counter" works and got saved.

Does anybody know what I did wrong in my code?

if ($input->urlSegment(1) === 'redirect') {
    $page->of(false);

    $page->redirect_last = time();
    $page->redirect_counter += 1;

    if ($page->save('redirect_counter')) {
        $session->redirect($page->website_url, 302);
    }
}

Thanks.

Link to comment
Share on other sites

You aren't saving the redirect_last field. Also, I don't think it is necessary to test the counter prior to redirecting. Try this and see if it fits your needs.

if ($input->urlSegment(1) === 'redirect') {
    $page->of(false);

    $page->redirect_last = time();
    $page->redirect_counter += 1;

    $page->save();

    $session->redirect($page->website_url, 302);

}

 

  • Like 1
  • Haha 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...