We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11793
    • 49 Posts
    This is directed at the PHP ninjas:

    I’ve extended MakeTable and MakeForm like so:

    include_once ('maketable.class.php');
    class MakeTableExtended extends MakeTable {
    	 
    	 function MakeTableExtended(& $xpdo) {
    	 	$this->__construct($xpdo);
    	 }
    	  function __construct(& $xpdo) {
            parent :: __construct($xpdo);
    
    
        }
    
    ... blah blah blah ...
    }


    I’ve done this to add some extra methods without touching the core classes.

    However, (and you saw this coming) Class MakeTable does not get its $this->xpdo variable set.

    Not a biggie, since it only seems to need it in a few places for error logging.

    I’ve tried a few different ways, such as manually setting the $xpdo variable both outside and inside the Class. Nothing seems to allow the parent Class to get its hands on $xpdo.
      • 3749
      • 24,544 Posts
      I’m confused. AFAIK, MakeTable is only available in MODx Evolution where there is no $xpdo variable (and the MakeTable constructor takes no argument).

      Did you find (or write) a Revolution version of the MakeTable class? I couldn’t find it.

      If so, did you try this in the constructor for your custom class?

      $this->xpdo = $xpdo;


        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
        • 11793
        • 49 Posts
        For those who came in late, get XPDO from SVN right now and you’ll notice that it comes with MakeTable and MakeForm.

        Don’t believe me? http://svn.modxcms.com/crucible/browse/xpdo/branches/1.0/xpdo/table/maketable.class.php?r=332

        I’ve had to extend both of these (using the technique above).

        One offending line is here:

        507 if ($this->xpdo->getDebug() === true)


        PHP complains that $this->xpdo does not exist for Class MakeTable. I can only guess it’s because I’ve created the object via an Extended Class.

        So, any PHP gurus want to weigh in a send some sage advice?

        This got omitted from my OP:

        XPDO 1.0 from SVN 8 Nov 2009, Modx 1.0.1, PHP 5, MySQL 5, Apache 2.2.
          • 26903
          • 1,336 Posts
          I’m seeing maketable.class.php in my revo installation under core/xpdo/table, if it came from evo it looks as though its been lifted into XPDO now. You can’t use this in evo as is, you have no $xpdo objects unless you’ve created them yourself. It looks as though you’re using evo 1.0.1 with a branch of svn intended for use by revo, not evo.

          However, you should be able to lift these refs out of this code, as you say its only used for debugging, just delete the relevant lines(only one as far as I can see) and you should be able to use it in evo without any $xpdo stuff.

            Use MODx, or the cat gets it!
            • 11793
            • 49 Posts
            Sorry, I’m confusing you with a lack of information.

            I’m using MakeTable in conjunction with XPDO 1.0 and MODX 1.0.

            I’m building a web app using XPDO. It uses MakeTable.

            I’m not trying to use MakeTable without XPDO!

            So yeah, MODX 1.0 has no XPDO in it, I’m using XPDO inside MODX snippets as an imported Class.
              • 26903
              • 1,336 Posts
              Ah, Ok got you now, well this should work, because MakeTable has no __construct() PHP 5 should look for a function namd MakeTable() which exists.
              For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class

              Ok, this is probably just bad formatting in the above post but are you getting any other errors? The line :-
              parent :: __construct($xpdo);
              should really be
              parent::__construct($xpdo);
              i.e no spaces I believe.
                Use MODx, or the cat gets it!
              • MakeTable and MakeForm are designed exclusively for use with xPDO, and can be used with Evo or Revo. But they are also not going to be in the final release as they do not belong in the model layer IMO; they should be an Extra available from the repository.

                Regardless, to extend them, all you need do is override the __construct($xpdo) and call parent::__construct($xpdo) in the extended constructor; just make sure you pass in your xPDO instance when creating the MakeTable instance.
                function __construct(& $xpdo) {
                    parent::__construct($xpdo);
                }

                  • 28215
                  • 4,149 Posts
                  To doubly state Jason’s point:

                  - MakeForm and MakeTable will not be in the final xPDO release for MODx Revolution.
                  - MODx Revolution in branches/2.0 SVN (and will so in beta5) be using xPDO 2.0 - not 1.0. This is PHP5-only xPDO.
                    shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com