We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6059
    • 45 Posts
    I tried to create a resource from snippet, the script was running fine in Revo 2.0.7 but now i get error. I tried a simple snippet to create a resource an get the same error.

    Here is the snippet code

    <?php
    $c = $modx->newObject('modResource');
    $c->set('pagetitle', 'tester');
    $c->save();


    and here the error

    Fatal error: Call to a member function getOption() on a non-object in /var/www/vhosts/mosega.com/httpdocs/core/model/modx/modresource.class.php on line 665

    Hope someone can help me here.
      • 26903
      • 1,336 Posts
      Hmm, looking at the code fail point its trying and failing to get a context from the new objects fields, try adding this line :-

      $c->set(’context_key’, ’web’);

      before your pagetitle set
        Use MODx, or the cat gets it!
        • 6059
        • 45 Posts
        Same error
          • 6059
          • 45 Posts
          Quote from: shamblett at Jun 20, 2011, 08:57 AM

          Hmm, looking at the code fail point its trying and failing to get a context from the new objects fields, try adding this line :-

          $c->set(’context_key’, ’web’);

          before your pagetitle set


          I need to correct me, this help me wonderfull. I only need to manualy clear the cache after insert the line that was all.
            • 6059
            • 45 Posts
            Sorry but i need to ask again, i thought the Problem would be solved but i get no error if i create newObject(’modResource’) as admin loged in all gone fine. But if i try the same script no logged in as admin i get the error from above. Hope someone of you has an idea.
              • 6059
              • 45 Posts
              Ok i think i got it now. Seems to be a user rights problem. After add right to the users i testet with it runs now. I hope this was the problem.
                • 31246 ☆ A M B ☆
                • 428 Posts
                @cschimanski Thanks, five hours spent in vain, could not understand, why in one browser I can create a resource from front, and from another was not present. There was all in the rights of the user.
                  Valentin Rasulov - Industrial design (Hobbies - Web Development)
                  Development not standard projects on CMF MODx Revolution.
                  Small sample of extensions