dps123

JSON Feed to Update Processwire

Recommended Posts

Hi,

I have a JSON feed that I need to grab and update some pages and fields within ProcessWire. I've created a template with my code that I am going to use. I have fallen at the first hurdle though. I need to first select the pages that are using my specific template as those are the ones that I need to update with the JSON data. When I do this:

$my_pages = $pages->find("template=my_template");

Error: Call to a member function find() on a non-object

Could someone point me in the right direction?

Thanks!

Share this post


Link to post
Share on other sites

If you're using the api in classes or functions these variables are not available as such. You'd need to use $this->wire('pages') or wire('pages') depending on the current scope.

  • Like 4

Share this post


Link to post
Share on other sites

If you haven't, you can read a bit in the docs here: https://processwire.com/api/modules/

Depending on what your module / class has extended, you may also use $this->pages->find()

And if you use procedural functions, you can use

function myFunction() {
    $pages = wire('pages');
    $pages->find();
    ...
Edited by horst
  • Like 3

Share this post


Link to post
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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By theoretic
      Hi there! And thanks for Processwire which i like very much.
      Got a problem while trying to update from 3.0.65 (with admin theme UIkit ) to 3.0.78 . Tried to do it both via ProcessWireUpgrade module and by copying/replacing the files and dirs manually. In every case i got the problem with UIKit admin theme. The first try to reload any admin page after update gives the following errors:
      Notice: Undefined variable: adminTheme in D:\work\sites\home\sea.dev\webroot\site\modules\AdminThemeUikit\init.php on line 121 Fatal error: Call to a member function get() on null in D:\work\sites\home\sea.dev\webroot\site\modules\AdminThemeUikit\init.php on line 121 It is officially recommended to reload the page several times after update to get the admin interface functional again, but it's not my case. The problem still persists. It's obvious that $adminTheme is not initialized. Reverting back to /wire dir of version 3.0.65 removes the problem. Switching to default admin theme and then updating to 3.0.78 makes the admin interface fully functional -- but switching to UIKit admin theme leads to the error again.
      Will appreciate any help. Thanks in advance!
    • By celfred
      Hello,
      I'm desperately trying to update my website to PW 3.0.62 and I'm facing issues to to module compatibility. I was stuck with Pages2Pdf which I managed to solve bu updating the module from Github, but now it's the Pages Web Service module... and this time, I don't know wht to do
      The Module is found there. But it is quite old and I can't find it in the modules catalogue... and my site is making quite a use of it (I can't think of a way to do otherwise, sorry...)
      After adding the FileCompiler=0 to the module pages, the error I'm stuck with is :
      Fatal error: Class 'WireData' not found in /home/celfred/PlanetAlert/site/modules/ServicePages/ServicePages.module on line 22
      and I have no idea on what to do... I must admit I'm not a programmer but a middle-school teacher... (for your information, here's the site I'm talking about : http://planetalert.tuxfamily.org ) but I'm struggling hard to solve the different issues I have to face and I'm wlling to understand things. I have just spent many hours trying to make 2.8 work on my localhost (and it seems ok ) but I'd like to switch to 3.x to prepare the future
      If anyone had the will to spend a few minutes to try and help me, I would greatly appreciate.
      Thanks in advance !
      If you need more information to understand my problem, feel free to ask.
    • By hellomoto
      I want to implement tables with Dynatable populated via ajax. Here's what I could muster:
      if($config->ajax) { $results = $pages->find($sanitizer->selector()); foreach($results as $r) $array[] = [ $r->title, $r->modified ]; header("Content-type: application/json"); echo json_encode($array); exit; } $content .= <<<EOT <table id="my-ajax-table"></table> <script> $("#my-ajax-table").dynatable({ dataset: { ajax: true, ajaxUrl: '.', ajaxOnLoad: true, records: [] } }); </script> EOT; But that's really nothing. Pro tips?
    • By thmsnhl
      Hi everyone,
      I've recently hired at a new company and here I am evaluating the abilities of ProcessWire for our projects.
      I was able to meet almost every requirement so far, but there is one point I couldn't find an adequate solution for: outputting data to json.
      I am aware of modules like https://modules.processwire.com/modules/pages2-json/ (which does not seem to work for me) but I thought with a function like wireEncodeJSON this should be much cleaner. What I would like to achieve is outputting pages with according field values into an array to use this within javascript.
      My first attempt on this was:
      $jsontestOne = $pages->find(1001)->children(); echo wireEncodeJSON($jsontestOne); which outputs 
      [{}] and afterwards I tried that one:
      $jsontest = $pages->find("template=basic-page")->getArray(); echo wireEncodeJSON($jsontest); which outputs 
      [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},...] Maybe you can point out where my mistake is.
       
      Thanks in advance!
    • By Salemoche
      Hello

      I've just started my first processwire project and have set the back end to my liking. Upon starting the front end of my site I encountered a very strange problem: The CSS file is not updating.
      I started off and soon the problem occured. I then simply copied the contents of main.css to a new main2.css file, changed the code in the template file, and it worked again. Thinking it was a one time thing I continued, but it didn't take long for the problem to happen again.
      Locally the files are changed and the html code of my project is updating normally, but when I inspect the page, the changes in the CSS file are nowhere to be seen.

      I'm using MAMP to create the local server and Koala to compile my SASS Code.  I'm new to processwire and am still pretty early in my web developer career, nontheless I'm very confused about what's happening, since the problem is only partially occuring in the CSS file and not in the HTML (or php) file.
      Does anyone have an idea as to what the problem could be?
      Thanks in advance