We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27449
    • 211 Posts
    Hi all....
    I’m try to understand the revolution modx huh It’s to different...

    I the latest version of modx I created modules but this version don’t have, then I created a namespace
    and I’m trying create a new Document when I run this namespace.

    Please can you tell me how I create new documents automaticaly on the revolution modx?

    On the latest version:

    require_once(’document.class.inc.php’);

    $doc = new Document();

    $doc->Set(’parent’,5);
    $doc->Set(’alias’,index);
    $doc->Set(’pagetitle’,’teste’);
    $doc->Set(’template’,’Geral’);
    $doc->Set(’published’,1);
    $doc->Set(’cacheable’,0);
    $doc->Set(’hidemenu’,1);


    $doc->Save();



    Thanks
      • 3749
      • 24,544 Posts
      <?php
      $doc = $modx->newObject('modDocument');
      
      $doc->set('parent',5);
      $doc->set('alias',index);
      $doc->set('pagetitle','teste');
      $doc->set('template','Geral'); /* I think you'll need the template's ID here */
      $doc->set('published',1);
      $doc->set('cacheable',0);
      $doc->set('hidemenu',1);
      
      $doc->setContent('<p>This is my content</p>');
      
      $doc->save();
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 32773
        • 118 Posts
        Quote from: BobRay at Oct 02, 2010, 01:13 PM

        <?php
        $doc = $modx->newObject('modDocument');
        
        $doc->set('parent',5);
        $doc->set('alias',index);
        $doc->set('pagetitle','teste');
        $doc->set('template','Geral'); /* I think you'll need the template's ID here */
        $doc->set('published',1);
        $doc->set('cacheable',0);
        $doc->set('hidemenu',1);
        
        $doc->setContent('<p>This is my content</p>');
        
        $doc->save();


        Thank you. A good example of how to insert a TV but a new resource?
          • 4971
          • 964 Posts
          You mention that you used to make modules in Evo...
          Revo has CMP -- custom manager pages, which replaced modules...
          try them.

          Resources or documents are for the front-end, CMP are for the manager.
            Website: www.mercologia.com
            MODX Revo Tutorials:  www.modxperience.com

            MODX Professional Partner
            • 4172
            • 5,888 Posts
            Quote from: x3m4ik at Oct 02, 2010, 01:42 PM

            Quote from: BobRay at Oct 02, 2010, 01:13 PM

            <?php
            $doc = $modx->newObject('modDocument');
            
            $doc->set('parent',5);
            $doc->set('alias',index);
            $doc->set('pagetitle','teste');
            $doc->set('template','Geral'); /* I think you'll need the template's ID here */
            $doc->set('published',1);
            $doc->set('cacheable',0);
            $doc->set('hidemenu',1);
            
            $doc->setContent('<p>This is my content</p>');
            
            $doc->save();


            Thank you. A good example of how to insert a TV but a new resource?

            An example with TVs. See formit2resource: http://modxcms.com/forums/index.php/topic,54204.msg313114.html#msg313114
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 3749
              • 24,544 Posts
              Here is one way:

              <?php
              $template = $modx->getObject('modTemplate',$modx->resource->get('template')));
              
              $fields = array(
                  'name'=>'NewTV',
                  'type'=>'option',
                  'caption'=>'New TV',
                  'description'=>'My New TV',
                  'elements'=> 'red||blue||green',
                  'default_text'=>'red',
                  'display'=>'default'
                );
                  
              $tv = $modx->newObject('modTemplateVar', $fields);
              
              
              $intersect = $modx->newObject('modTemplateVarTemplate');
              $intersect->addOne($tv);
              $intersect->addOne($template);
              $intersect->save();
              
              $tv->setValue($id,'value'); /* ID is the id of the resource you want to set the TV for */
              
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 32773
                • 118 Posts
                I mean, how to set a value for an already established TV to create a document using the Api?
                Or is it impossible until I know the ID document?
                Sorry, I’m using translate.google
                  • 3749
                  • 24,544 Posts
                  Quote from: x3m4ik at Oct 02, 2010, 10:46 PM

                  I mean, how to set a value for an already established TV to create a document using the Api?
                  Or is it impossible until I know the ID document?
                  Sorry, I’m using translate.google

                  You do need to know the document ID, but if you just created it and saved it, you can retrieve it with getObject() and then set the TV:

                  <?php
                  $resource = $modx->newObject(('modDocument', array('name'=>'MyNewDoc'));
                  $resource->save();
                  
                  $resource = $modx->getObject(('modDocument', array('name'=>'MyNewDoc'));
                  $id = $resource->get('id');
                  
                  $tv = $modx->getObject('modTemplateVar',array('name'=>'MyTv'));
                  
                  $tv->setValue($id,'value');
                  $tv->save()
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 27449
                    • 211 Posts
                    Thanks for your reply.

                    But I have a problem sad
                    When I try to run the file I have the error below:

                    Notice: Undefined variable: modx
                    Fatal error: Call to a member function newObject() on a non-object


                    Please can you tell me if I need to call some file or what is the problem?

                    Thanks
                      • 19534
                      • 183 Posts
                      If you’re not using your code within a modx context you have to create the modx object:

                      require_once 'YOUR_PATH_TO/config.core.php';
                      include_once MODX_CORE_PATH . 'model/modx/modx.class.php';
                      $modx= new modX();
                      
                        Add-On to easily manage your multilingual sites: Babel