View more context


Vincent Piotrowski

Hello, I had a question about the feasibility or approach I should take to programatically build a list of pages in SilverStripe. The data for the pages lives in a separate JSON API and the fields are uniform and simple (e.g. title, description, etc). I need to run the import once a day. My first thought was to generate a CSV file from the API then use CsvBulkLoader to create the pages. Is this a good approach to take? Are there approaches that would be simpler?


Depends on how familliar you are with REST (?) APIs vs CSV. For me, the CSV is an extra layer of complexity that isn't needed.

✔️ (1)

Off the top of my head:

  1. $pages = $this->getPageDataFromAPI() // Returns a blob of JSON. Assumes an array of pages
  3. // Assumes API data looks something like this, or can be modified to look like this:
  4. [
  5. {
  6. "Title": "Some title",
  7. "Description": "Some description"
  8. },
  9. {
  10. "Title": "Some title 2",
  11. "Description": "Some description 2"
  12. }
  13. ]
  15. foreach ($pages as $page) {
  16. $array = json_decode($page, true);
  18. // TODO
  19. // Check wether the page has unpublished changes. If so, just use ->write()
  20. // Other implemenmtation specific stuff
  21. SiteTree::create($array)->publishRecursive();
  22. }
Vincent Piotrowski

Awesome thanks, I'm more comfortable with REST so that is very helpful. Thanks again!

👍 (1)

Make your API call, iterate over the result, create new SiteTree records based on what the API endpoint returns.

👍 (1) ✔️ (1)

Hey, I’m looking at the new logout functionality with the interstitial logout form. Is there any way to set BackURL for that form? We’re adding a get var to the logout link but that seems to be stripped before it even gets to Security#logout so the value of the BackURL form field always falls back to the referrer URL.


Really? getBackURL just checks GET and POST vars.


I’m currently overriding that method in a custom LogoutHandler


That’s currently working and since it is in a LogoutHandler I assume it won’t leak into any other uses of getBackURL.


Just noticed that the back URL is probably not being set because the URL we’re building is malformed. It has two ? characters since the security ID is being added by SS too.


And when that URL is properly formed the interstitial logout form isn’t displayed.