We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    ok - not sure what is going on here, my php kung-fu is pretty weak.

    this used to work:

    class ExtData extends xPDOSimpleObject {
    
    	function __construct(modX & $modx,array $config = array()) {
    						
    		$this->modx =& $modx;
    				
    		$config = array_merge(array(
    			'user' => $this->modx->getLoginUserID(),
    			'debug' => 'true',
    			),$config);
    		
    		include_once('exthelpers.class.php');
    		
    		$this->modx->addExtensionPackage('extdata',"[[++core_path]]components/extdata/model/");
    		
    		$this->modx->lexicon->load('extdata:default');
    		
    		$this->modx->log(modX::LOG_LEVEL_ERROR,'cons 5');
    		
    		//$this->modx->setLogLevel(modX::LOG_LEVEL_DEBUG);
    		
    		if(!$_SESSION['artist']){
    			$_SESSION['artist'] = 'newartist';
    		}
    				
    	}



    I called it from:

    <?php
    $classfile = dirname($modx->getOption('core_path')).'/core/components/extdata/controllers/extdata.class.php';
    
    if (file_exists($classfile)) {
        $output = include_once $classfile;
    } else {
        $modx->setLogTarget('ECHO');
        $modx->log(modX::LOG_LEVEL_ERROR,'class not found at: '.$file);
    }
    
    
    
    $scriptproperties['queryData']  = (isset($queryData)) ? $queryData : "";
    $scriptproperties['gigid']  = (isset($_POST['edit_gig'])) ? $_POST['edit_gig'] : "";
    $scriptproperties['mp3id']  = (isset($_POST['edit_mp3'])) ? $_POST['edit_mp3'] : "";
    $scriptproperties['discid']  = (isset($_GET['discid'])) ? $_GET['discid'] : "";
    $scriptproperties['placeHolder']  = (isset($placeHolder)) ? $placeHolder : "";
    
    
    if($_GET['edit_mp3']){
    
    			// we must be trying to edit an mp3!!
    			//echo 'editing an mp3!!';
    
    			$scriptproperties['queryData']  = 'GetOneMp3';
    			$scriptproperties['mp3id']  = $_GET['edit_mp3'];
    
    }
    
    /*
    echo '<pre>';
    print_r($scriptproperties);
    echo '</pre>';
    exit();
    */
    
    if(class_exists('ExtraData') != true) {
       $ExtraData = new ExtData($modx,$scriptproperties);
    }
    
    
    $output = $ExtraData->getData($scriptproperties,$hook);
    
    return $output;





    Now, I'm not sure what is happening or how to fix it - if I remove all the $this-> from the constructor it will at least get through that, but as soon as another function in the class gets called $this-> breaks it again. I'm thinking that $modx is not getting passed into the class properly?

    any ideas?

    this is the error:

    Fatal error: Call to a member function getOption() on a non-object in /home/canad036/public_html/core/xpdo/om/xpdoobject.class.php on line 692
    



      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 8386 ☆ A M B ☆
      • 160 Posts
      I am not sure why you are passing $modx as reference twice, can you remove the & before the $modx in the constructor param and also on the $this->modx =;

      class ExtData extends xPDOSimpleObject {
               function __construct(modX $modx, array $config = array()) {
                   $this->modx = $modx;
      }
        • 41574
        • 14 Posts
        Hey Sean did you ever figure out why you were getting that fatal error? I am having the same problem.
          • 3749
          • 24,544 Posts
          I think passing $modx as a reference variable may be necessary because lexicon->load() needs to modify the real MODX object, not a copy of it.

          Also, since it's an xPDO object, it should be instantiated with $modx->newObject() rather than new().
            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