Jump to content

Recommended Posts

Posted

Hi,

is there a way to set the "created" date while creating a page via API?

I tried this:

$page->created = $data['crdate'];           // $data['crdate'] is an timestamp like 1321279318

But it won't work...

Greets,

Nico

Posted

It works for me...

<?php
$page->created = time();
$page->save();

// outputs current timestamp
echo $page->created;

---

ops but after removing it outputs the old again, so it's not saved.

Posted

I solved this with SQL:

First save normally and after this:

$sql = "UPDATE `pages` SET `created` = '".date('Y-m-d H:i:s', $data['crdate'])."', `modified` = '".date('Y-m-d H:i:s', $data['tstamp'])."' WHERE `name` = '".$page->name."';";

$update = wire('db')->query($sql);
Posted

The $page->created and $page->modified properties are meant to be internal and consistent with actual page creation and modification dates in PW, so they aren't things that can be modified by the API. While you can go directly in and modify it with SQL, it's better to create your own properties using PW date fields. There's nothing that you can't do with your own fields that you can do with those internal created/modified fields. However, at present, I don't think it does any harm to modify them in SQL, but just saying that it's not a best practice.

  • Like 1

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...