We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    I'm having a problem with the custom lexicon not loading in an extra, not sure where I am going wrong:


    Here is how I am calling the class:

    <?php
    $output = '';
    
    $flowcore = $modx->getOption('core_path').'components/modflowthrough/model/';
    
    $flow = $modx->getService('modflowthrough', 'modFlowThrough', $flowcore, $scriptProperties);
    
    
    if (!$flow instanceof modFlowThrough){
    
    	return 'Insantiation failed';
    
    }else{
    
    foreach($_GET as $key => $value){
    
      $scriptProperties[$key] = $value;
    
    }
    
    $scriptProperties['currentResourceId'] = $modx->resource->get('id');
    
    $hook = isset($hook) ? $hook : '';
    
    $output = $flow->$scriptProperties['function']($scriptProperties, $hook);
    
    }
    
    return $output;



    And the class:


    class modFlowThrough {
    
    	function __construct(modX & $modx,array $config = array()) {
    	
    		$this->modx =& $modx;
    		
    		$this->modx->setLogLevel(xPDO::LOG_LEVEL_DEBUG);
    		
    		$this->modx->setLogTarget('ECHO');
    		
    		$basePath = $this->modx->getOption('modflowthrough.core_path', $config, $this->modx->getOption('core_path').'components/modflowthrough/', true);
    				
    		$this->config = array_merge(array(
    			'flowBasePath' => $basePath,
    			'flowCorePath' => $basePath,
    		),$config);
    		
    		if (!$this->modx->addPackage('modflowthrough',$this->config['flowCorePath'].'model/','flow_')) {
    
    		    return '<br />There was a problem adding your package.<br />';exit();
    		}
    		
    		// Load the package lexicon
    		if(!$this->modx->getService('lexicon','modLexicon')){
    			
    			echo 'error loading lexicon';
    			
    		}else{
    			
    			$this->modx->lexicon->load('modflowthrough:default');
    		}
    		
    		
    		echo $this->modx->lexicon('modflowthrough.add_Program_failed');exit();
    }




    Seems to me that modx should need a path to the modflowthroug core at some point in order to ~find~ it's lexicon? right?




    }

    This question has been answered by BobRay. See the first response.

      *** 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
    • discuss.answer
      • 3749
      • 24,544 Posts
      The lexicon calculates the path from the core path field of the namespace.

      Check in System -> Namespaces. Make sure your package has a namespace there, that the core path entry is correct, and ends with a slash.
        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
        • 26503
        • 620 Posts
        Is it possible to check/set a namespace in a snippet?


        Quote from: BobRay at Mar 05, 2014, 01:54 PM
        The lexicon calculates the path from the core path field of the namespace.

        Check in System -> Namespaces. Make sure your package has a namespace there, that the core path entry is correct, and ends with a slash.
          *** 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
          • 3749
          • 24,544 Posts
          Yes it is, but for a typical extra, the namespace is one of the first things created when the transport package is installed. MyComponent, for example, does this automatically for you, but you can do it yourself pretty easily in the build.transport.php file that creates your extra package.

          $builder = new modPackageBuilder($modx);
          $builder->createPackage(PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE);
          
          $builder->registerNamespace(PKG_NAME_LOWER, false, true, 
              '{core_path}components/' . PKG_NAME_LOWER . '/', 
              '{assets_path}components/' . PKG_NAME_LOWER . '/');
          
            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
            • 26503
            • 620 Posts
            right, but I'm trying to find out if the namespace even exists in a snippet, then set it if it does not. So far the only way I am seeing to do this is by querying the namespace table directly, whipping through the results & adding a namespace if not found.



            Quote from: BobRay at Mar 06, 2014, 11:47 AM
            Yes it is, but for a typical extra, the namespace is one of the first things created when the transport package is installed. MyComponent, for example, does this automatically for you, but you can do it yourself pretty easily in the build.transport.php file that creates your extra package.

            $builder = new modPackageBuilder($modx);
            $builder->createPackage(PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE);
            $assetsPath = '{assets_path}components/' . PKG_NAME_LOWER . '/';
            $builder->registerNamespace(PKG_NAME_LOWER, false, true, 
                '{core_path}components/' . PKG_NAME_LOWER . '/', 
                $assetsPath);
            
              *** 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
              • 26503
              • 620 Posts
              this is what I would up doing - seems messy to me... but it does work.

              // check the namespace
              $namespace = 'mynamespace';
              
              $path = '{core_path}components/mynamespace/';
              
              $query = $modx->query("SELECT * FROM `modx_namespaces` where `name` = '".$namespace."'");
              
              if(!$query->fetch(PDO::FETCH_OBJ)){
              
              	$newNamespace = "insert into `modx_namespaces` (name,path) values ('".$namespace."','".$path ."');";
              
              	$query = $modx->query($newNamespace);
              
              }
                *** 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
                • 3749
                • 24,544 Posts
                Using xPDO would make it a little cleaner:

                $nameSpace = $modx->getObject('modNamespace', array('name' => 'mynamespace'));
                
                if (!$nameSpace) {
                   $nameSpace = $modx->newObject('modNamespace');
                   $nameSpace->set('name', 'mynamespace');
                   $nameSpace->set('path', '{core_path}components/mynamespace/');
                   $nameSpace->save(); 
                }


                If it's in a package resolver, you have to add this at the top:

                $modx =& $object->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
                  • 26503
                  • 620 Posts
                  Funny I was trying something pretty much exactly like that, but it was not working.... will try your code for sure smiley

                  thanks again!



                  Quote from: BobRay at Mar 06, 2014, 05:36 PM
                  Using xPDO would make it a little cleaner:

                  $nameSpace = $modx->getObject('modNamespace', array('name' => 'mynamespace'));
                  
                  if (!$nameSpace) {
                     $nameSpace = $modx->newObject('modNamespace');
                     $nameSpace->set('name', 'mynamespace');
                     $nameSpace->set('path', '{core_path}components/mynamespace/');
                     $nameSpace->save(); 
                  }


                  If it's in a package resolver, you have to add this at the top:

                  $modx =& $object->xpdo;
                    *** 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