We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Articles and its children are quite different than ordinary resources. Among other things, they are given extra fields in the site_content table. It is very complicated to try to meddle with it in any way.

    If you examine the code in core/components/articles/model/articles/article.class.php you will see that it uses a few classes that extend the usual MODx classes. For example, around line 28 you will find
    class Article extends modResource {
    ...
    ...
            $this->set('class_key','Article');
            $this->set('show_in_tree',false);
            $this->set('richtext',true);
            $this->set('searchable',true);
    ...
    

    Then again around line 441 you can see that it extends modResourceCreateProcessor
    class ArticleCreateProcessor extends modResourceCreateProcessor {
    ...
    ...
            $this->setProperty('searchable',true);
            $this->setProperty('richtext',true);
            $this->setProperty('isfolder',false);
            $this->setProperty('cacheable',true);
            $this->setProperty('clearCache',true);
            $this->setProperty('class_key','Article');
    

    Likewise it extends modResourceUpdateProcessor around line 578.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 50578
      • 2 Posts
      Quote from: BobRay at Mar 15, 2012, 08:29 PM
      Thanks for the kind words. smiley

      Creating a new resource in MODX Revolution is pretty simple. You just ask for a new object, set the fields, and save it. The code below, with no modifications, will create a new resource. In fact, you don't need the setContent() call. The only required fields are the pagetitle and alias.

      <!--?php
      
      $newResource = $modx--->newObject('modResource');
      
      $newResource->set('pagetitle', 'New Page');
      $newResource->set('alias', 'newpage')
      // etc.
      
      $newResource->setContent('<p>Some Content</p>');
      
      $newResource->save();


      You can also set the fields and call the resource/create processor. That's a more reliable way to do it but the code is a little more complex.

      Your project sounds pretty challenging, but creating the resources won't be the hard part. wink


      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html

      Very useful! My question is how can i add the resource as a child of another resource?
        • 4172
        • 5,888 Posts
        if you know the id of the parent, then


        $newResource = $modx->newObject('modResource');
         
        $newResource->set('pagetitle', 'New Page');
        $newResource->set('alias', 'newpage');
        $newResource->set('parent', $parent);
        // etc.
         
        $newResource->setContent('<p>Some Content</p>');
         
        $newResource->save();


          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 50578
          • 2 Posts
          Quote from: Bruno17 at Jun 06, 2015, 09:15 PM
          if you know the id of the parent, then


          $newResource = $modx->newObject('modResource');
           
          $newResource->set('pagetitle', 'New Page');
          $newResource->set('alias', 'newpage');
          $newResource->set('parent', $parent);
          // etc.
           
          $newResource->setContent('<p>Some Content</p>');
           
          $newResource->save();



          Thanks a lot Bruno!