We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37260
    • 8 Posts
    Hello,

    I have a simple problem: I don't know how to use the resource/update processor!
    I have tried something like this:
     $my_doc = array(
          'id' => '123'
          ,'pagetitle' => 'my title'
          ,'content' => 'my content'
    );
    $modx->runProcessor('resource/update',$my_doc);
    


    And all I've got in return is an error:
    Fatal error: Call to a member function getOption() on a non-object in /srv/http/website.com/public_html/modx/core/model/modx/processors/resource/update.class.php on line 277 [...]

    The line 277 of the resource/update class is this:
     $this->isSiteStart = ($this->object->get('id') == $this->workingContext->getOption('site_start') || $this->object->get('id') == $this->modx->getOption('site_start'));


    Could someone tell me how to do this?
    Thanks! [ed. note: kiguane last edited this post 11 years, 11 months ago.]
      • 33968
      • 863 Posts
      Weird, $this->workingContext should be set earlier (line 126) but in your case no valid Context object is retrieved. Where are you running this code, in the manager?
      $this->workingContext = $this->modx->getContext($this->getProperty('context_key'));
      

      Try passing context_key in your $my_doc array and see if that works:
      $my_doc = array(
            'id' => '123'
            ,'pagetitle' => 'my title'
            ,'content' => 'my content'
            ,'context_key' => 'en'
      );
      $modx->runProcessor('resource/update',$my_doc);
      
        • 1778
        • 659 Posts
        Hello
        did you try
        $my_doc = array(
        'id' => 123  // ID should be an integer not a string ! maybe the source of not returned object
        ,'pagetitle' => 'my title'
        ,'content' => 'my content'
        ,'context_key' => 'en'
        );
        $modx->runProcessor('resource/update',$my_doc);
        


        Hope this helps
        Cheers

          • 37260
          • 8 Posts
          Hi!

          Sorry for the late reply, I thought I had subscribed to the thread but in fact not!

          I have tried with the added context_key ('web' in my case) and it asked me for a mandatory alias which I also provided by adding the corresponding alias key... and then it seems to work!
          So thank you for that!


          But it seems odd to have to provide all this information since I would have thought that only an id would be required for an update...

          My code is running as a post-hook on a Formit page (a variation on the famous formit2resource)...

          Thank you to both of you!

            • 33968
            • 863 Posts
            ...well spotted anso, I hadn't picked that up. But yes the id should definitely be an integer.

            @kiguane - I'm also not sure why anything other than the id is required to perform the update. Glad you got it working for now though.