Nico Knoll Posted November 17, 2011 Share Posted November 17, 2011 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 Link to comment Share on other sites More sharing options...
Nico Knoll Posted November 17, 2011 Author Share Posted November 17, 2011 Well, I think I try to solve this with SQL... Link to comment Share on other sites More sharing options...
Soma Posted November 17, 2011 Share Posted November 17, 2011 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. Link to comment Share on other sites More sharing options...
Nico Knoll Posted November 17, 2011 Author Share Posted November 17, 2011 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); Link to comment Share on other sites More sharing options...
ryan Posted November 18, 2011 Share Posted November 18, 2011 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. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now