We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3031
    • 3 Posts
    Hey guys!
    Ive got a trouble, ive no idea how to create new document.
    There is separated php script (in the root), where i use modxapi.php to create modx instance and docapi.class.inc.php but it doesn’t work. (there were errors in docapi.class.inc.php, i fixed them up but it made docapi.class.inc.php go crazy).
    Well, im really suprised that i didnt find native tools to do it.
    So are there any ways how to create new document in separeted php file?
    (or i gotta get into database’s structure and write data right into it?)
      • 5340
      • 1,624 Posts
      All the documents are saved in the database.
      There is no need to create a php file.

      To create a document just Click on the "New Resource" button.
        • 3031
        • 3 Posts
        no, you didnt get me
        i clearly understand how to create document into the cms but it aint i need

        well i have to sites let it be A and B.
        A-site doesnt contain modx and it just collects information in database
        B-site is modx site
        so i need to trasfer new records from A to B via php script thats why i have php script on B site that gets information via post request in predefined structure then transforms it and saves into the modx database and thats why i gotta know how to create new document in separeted (extern) php file.
        so how can i do it?
          • 5340
          • 1,624 Posts
          My guess is that you want to create a snippet.

          Am I right?

          If so do this.

          Create a snippet and name it mySnippet.

          paste this

          <?php
          include_once('path/to/mysnippet.php');
          ?>


          Modify the path to include to your B php file. They must be on the same server


          In the modx document you want to display the output of your php file enter

          [[mysnippet]]

          Save and preview you document.

          You might need to modify your B code.

            • 3749
            • 24,544 Posts
            I think behod wants to create a MODx document in PHP code in a snippet.

            If so -- take a look at the code of the NewsPublisher snippet (should be included in your install). It creates new documents from the user’s input.
              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
              • 16278
              • 928 Posts
              To create new documents on site B containing the incoming data from site A via a hook into the API within a script (snippet), have a look at Docmanager, which does what I think you were trying to do in the first place. It is a class library, and you can create a document as an object and update it in normal object-oriented ways with great ease. No need to hack core files or create database records directly.

              Docmanager is in the repository at http://modxcms.com/extras/package/108. This offers the version for Revolution (MODx 2). If you want the version for Evolution (up to MODx 1.0), click on Previous Releases and download 0.5.3b. NB change the shortcut <? script tag to <?php if you need to.

              Hope this is what you are looking for smiley KP
                • 3031
                • 3 Posts
                Thanx fellas!!!
                (the 2 last answers are really what i need)