We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40122
    • 330 Posts
    OK - I give up!

    I cannot use the info in Bobs guides as the Snippet 'CreateXpdoClasses' will not save.

    I have tried about 3 versions of PDO queires from all over the ModX sites and wiki and all give me the same error:

    Parse error: syntax error, unexpected T_VARIABLE


    Frustratingly, will have to revert back to Evo or try and write everything from scratch!
    • Yes. The mysql drivers and the PDO drivers maintain completely separate connections.

      However, I would strongly advise that when you do have the time, you go through Bob's tutorial again until you see how it works.

      His retrieval function uses getCollection(), which allows you to iterate through the rows. You could use any of the other "get" functions xPDO (or PDO) provides http://rtfm.modx.com/display/xPDO20/Retrieving+Objects

      The main thing this tutorial does is provide a simply way of converting your (existing) table to an xPDO schema so that you only need minimal arguments to the various data manipulation functions. With the schema, xPDO knows where everything is and what its data types and relations to other tables are, leaving you nothing more to do than the basic operations of Create (insert), Read (select), Update (update), Delete (delete) - the basic CRUD operations.
        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
        • 3749
        • 24,544 Posts
        Do you mean that you couldn't download the snippet at Bob's Guides? I just tried it and it worked for me.

        Did you try using a different browser?

        Or is it something else?


        ------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using.
        MODX info for everyone: http://bobsguides.com/modx.html
          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
          • 40122
          • 330 Posts
          Quote from: BobRay at Sep 18, 2012, 06:52 AM
          Do you mean that you couldn't download the snippet at Bob's Guides? I just tried it and it worked for me.

          Did you try using a different browser?

          Or is it something else?

          I was able to download it fine but when I paste the PHP code into the snippet I create it will not save. I've experienced this before with JavaScript when I havent specified `type="text/javascript"`. Is this something similar?
          • Are you sure you gave it a name? If you don't fill in the required name field it won't save, and I find it easy to not notice the error message at the top when I do that (in fact, I just did that today while testing Bob's tutorial!)
              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
              • 40122
              • 330 Posts
              Quote from: sottwell at Sep 18, 2012, 08:30 AM
              Are you sure you gave it a name?

              Yes I did give it a name. I also tried saving it as a blank an then editing it and entering the PHP. - I should have clarified earlier: I am running 2.1.3 if that makes any difference (thanks for all the help! Such an odd issue!)
              • Do you have this problem with any other snippets (or any other elements)? The only time I've seen something like this was with security systems like suhosin. Especially since you appear to be able to save it empty, it sounds very much like suhosin or mod_security configuration that doesn't like something in the code being posted in the form.

                This explains the problem with mod_security

                http://wiki.modxcms.com/index.php/What_is_mod_security_and_how_does_it_affect_me
                  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
                  • 40122
                  • 330 Posts
                  OK - so I did and experiment and pasted the code in line by line to see which would not save. Apparently it doesnt like this block of comments:

                  /* Table names to process -- this is only necessary if your table prefix is
                   * the same as that of the MODx tables. You can send a comma-separated list
                   * of full table names. In that case the class name will be the table name 
                   * minus the prefix with any underscores removed and any letter after an 
                   * underscore in upper case.
                   *
                   * You can also send an array of arrays of tableName => className, 
                   * which allows you to specify the exact class name rather then letting
                   * MODx create it from the table name. Each inner array specifies a full
                   * table name and the class name to use.
                   *
                   * NOTE: This feature may not be implemented yet.
                   *
                   * Examples:


                  Dont ask me why.... I removed this and it seems to save fine. I will continue experimenting with it
                  • It may be the double dash -- since that's an sql comment tag, and can be used for sql injection

                    http://www.hackerscenter.com/index.php?/HSC-Guides/Web-App-Security/Sql-injection.html (about half-way down the page it describes using this for SQL injection)
                      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
                      • 3749
                      • 24,544 Posts
                      There is example PHP code in that comment just beyond the point you reached. That sounds like mod_security at work. I wonder if putting a star at the beginning of the lines with the PHP code would fix it.

                      mod_security can be really crazy sometimes. I've seen a number of reported cases where WordPress users couldn't save a post that contained the word "from" more than and another where mod_security choked on just the word "executive."

                      If you get a chance, see if adding the asterisks solves it and let me know so I can prevent this problem for others.



                      ------------------------------------------------------------------------------------------
                      PLEASE, PLEASE specify the version of MODX you are using.
                      MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 11 years, 8 months ago.]
                        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