We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37031
    • 93 Posts
    Hi guys! I have the following code which works well but I'm unsure if I'm calling $this->failure() properly to return an error:
    class scStudentAssignmentUpdateProcessor extends modObjectUpdateProcessor {
        
        public $classKey = 'scStudentAssignment';
        public $languageTopics = array('studentcentre:default');
        public $objectType = 'studentcentre.ass';
        
    	public function beforeSet() {
    		$comment = $this->getProperty('comment');
    		$saId = $this->getProperty('id');
    		$userId = $this->getProperty('userId');
    		$processorsPath = $this->getProperty('processorsPath');
    		
    		if (empty($comment)) { // check to see if the comment field is empty. if so throw error response
                $this->addFieldError('comment',$this->modx->lexicon('studentcentre.ass_err_ns_comment'));
            } else {
            	$response = $this->modx->runProcessor('mgr/assignments/scCommentCreate', array(
    					'comment' => $comment,
    					'student_assignment_id' => $saId,
    					'user_id' => $userId,
    				), array(
    					'processors_path' => $processorsPath,
    				)
    			);
    			
    			if ($response->isError()) {
    			    return $this->failure($response->getMessage());
    			}
            }
    
    		return parent::beforeSet();
    	}
    }
    
    return 'scStudentAssignmentUpdateProcessor';


    If I want to return a failure message from my processor, do I have to return it? Thank you!

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

    • discuss.answer
      • 3749
      • 24,544 Posts
      Yes, I think you do (and you want to bail out anyway rather than run the parent processor with an error condition).


      You can also use your own message rather than the processor's error message if you know what's wrong:

      return $this->failure('MyMessage');


      or

      return $this->failure($this->modx->lexicon('my_message_key'));
        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
        • 37031
        • 93 Posts
        Thanks Bob, much appreciated!

        PS: Your MODX book is great! And if you were ever thinking about putting out a second MODX book that covered advanced topics like CMPs and third-party components I would buy that one too... just saying smiley
          • 3749
          • 24,544 Posts
          Don't tempt me. I spent enough time on the first one. wink
            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