We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2364
    • 73 Posts
    Hola!
    I have simple component and want to process error info through $modx->error->failure($error_msg) but I get
    <b>Fatal error</b>:  Call to a member function failure() on a non-object in <b>/var/www/dev/modx/core/components/x/processors/mgr/getinfo.php</b> on line <b>19</b><br />

    $error_msg is a string. When I use "return $error_msg;" I got "Error: Code 1 - Message something not found (invalid ID)".
    $modx->error->failure($modx->lexicon(’x.error’)) - the same error.
    $modx->error->failure(’Some msg’) - working normal.
    How to process error message in right way.
      • 28215
      • 4,149 Posts
      So
      $modx->error->failure('We gots an error');


      works fine, but:

      $modx->error->failure($modx->lexicon('lex_entry'));


      doesn’t?

      You’re going to have to provide more code for us to help you. That should work fine, as long as you’re loading your connectors right.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 2364
        • 73 Posts
        I always get an error if I want submit some variable as message:
        $err1 = 'Msg 1';
        $err2 = $modx->lexicon('lex_entry').'Msg 2';
        $err3 = array('message' => 'Msg 3', 'code' => 321);
        return $modx->error->failure($err1); //error
        return $modx->error->failure($err2); //error
        return $modx->error->failure($err3); //error
        

        But following example working fine:
        return $modx->error->failure('Error message'); //working
        //and
        $error = new modError(&$modx,$error_msg);
        return $error->failure(); //working
        
          • 28215
          • 4,149 Posts
          Quote from: atma at Aug 14, 2009, 04:51 PM

          But following example working fine:
          return $modx->error->failure('Error message'); //working
          //and
          $error = new modError(&$modx,$error_msg);
          return $error->failure(); //working
          


          Whats your connector.php file look like? It doesn’t look like you’re loading that correctly.

          Is this in a processor that’s being accessed via AJAX? If so, how is that processor loaded?
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 2364
            • 73 Posts
            Yes, it accessing via AJAX (ExtJS, mgr context).
            In Ext constructor I have
            url: XComp.config.connector_url, //"connector_url":"\/assets\/components\/xcomp\/connector.php"
            baseParams: {
            action: ’mgr/getinfo’
            }

            connector.php
            require_once dirname(dirname(dirname(dirname(__FILE__)))).'/config.core.php';
            require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
            require_once MODX_CONNECTORS_PATH.'index.php';
            
            require_once MODX_CORE_PATH.'components/xcomp/model/xcomp/xcomp.class.php';
            $modx->xcomp = new XComp($modx);
            if (isset($_REQUEST['resource'])) {
                $modx->resource = $modx->getObject('modResource',$_REQUEST['resource']);
            }
            
            $path = $modx->getOption('processors_path',$modx->xcomp->config,$modx->getOption('core_path').'components/xcomp/processors/');
            $modx->request->handleRequest(array(
                'processors_path' => $path,
                'location' => '',
            ));
            

            And it working fine for $modx->error->success() in any case, $modx->error->success($response) for example...
              • 28215
              • 4,149 Posts
              What version of Revolution is this?
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 2364
                • 73 Posts
                Quote from: splittingred at Aug 14, 2009, 08:44 PM

                What version of Revolution is this?
                SVN rev.5639
                  • 28215
                  • 4,149 Posts
                  atma,

                  I cant seem to replicate any of this in my installation at all, and cant see why that’s happening. Could you do me a favor and do the following:

                  1. Post me the entire processor file that’s causing the error. You can attach it if you need.
                  2. Verify that your 3PC has a Namespace, a Lexicon, Lexicon Topic and a Lexicon Entry to test with.
                  3. Post me any stack trace PHP errors that occur.
                  4. Post me any related errors in core/cache/error.log

                  The only other thing I see is that you’re not loading the lexicon topic for your lexicon string; I’m not sure if that’s causing the problem, but it might be. You’ll need to call:

                  $modx->lexicon->load('mynamespace:mytopic');
                  
                    shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                    • 2364
                    • 73 Posts
                    Quote from: splittingred at Aug 14, 2009, 09:49 PM

                    1. Post me the entire processor file that’s causing the error. You can attach it if you need.
                    2. Verify that your 3PC has a Namespace, a Lexicon, Lexicon Topic and a Lexicon Entry to test with.
                    3. Post me any stack trace PHP errors that occur.
                    4. Post me any related errors in core/cache/error.log

                    1. My processor is very simple:
                    <?php
                    if ($_REQUEST['photo_id']) {
                    	$photo_id = $_REQUEST['photo_id'];
                    } else {
                    	return $modx->error->failure('ID can not be empty'); //Here working like a charm
                    }
                    $photo_info = $modx->xcomp->photos_getInfo ($photo_id); //return one dimensional array or NULL
                    if (!$photo_info) {
                    	$error = $modx->xcomp->getError(); //array with 2 keys: code, message
                    	$error_msg = $modx->lexicon('xcomp.error').': '.$modx->lexicon('xcomp.error_code').' '.$error['code'].' - '.$modx->lexicon('xflickr.error_msg').' '.$error['message']; //var_dump is string: Error: Code 01 - Message Wrong photo ID
                    	
                    	return $modx->error->failure($error_msg); //error
                    }
                    
                    return $modx->error->success('Success msg', $photo_info); //if $_REQUEST['photo_id'] not null and correct I get normal response which using for JsonStore
                    ?>
                    


                    2. My 3PC has a Namespace, a Lexicon, Lexicon Topic and a Lexicon Entry and all working fine in other calls.
                    3. All related logs are empty
                    4. core/cache/error.log is empty
                    Only in Fifebug I have response
                    <br />
                    <b>Fatal error</b>:  Call to a member function failure() on a non-object in <b>/var/www/dev/modx/core/components/xcomp/processors/mgr/photos/getinfo.php</b> on line <b>12</b><br />
                    
                    and not
                    {"success":false,"message":"Err msg","total":0,"data":[]...
                    which can be processed in ExtJS application
                      • 28215
                      • 4,149 Posts
                      Talk about a rare case. So I’m pretty sure it’s because you’re assigning a value to $error, which I think is a MODx reserved variable for connectors - it’s a reference to $modx->error. It’s there for backwards compatibility. We’ll make sure and address that in future versions, but for now, make sure and not use that as a variable name.

                      So changing this line:
                      $error = $modx->xcomp->getError(); //array with 2 keys: code, message

                      to something else, like this:
                      $myError = $modx->xcomp->getError(); //array with 2 keys: code, message


                      And then obviously change it in the other lines.

                      If that doesn’t work, this is a shot in the dark, but try using a different variable name than $error_msg. That might be a PHP reserved variable; might not.
                        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com