We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42544
    • 7 Posts
    I try to query from the mysql to the frontend web.
    by using the snippets below...

    name --> (codequery)
    CMP class --> ModReviews
    path --> ./core/components/modreviews/


    <?php
    	$mReview = $modx->getService('modreviews','ModReviews',
    	$modx->getOption('modreviews.core_path',null,
    	$modx->getOption('core_path').'components/modreviews/').'model/modreviews',$scriptProperties);
        
    	if (!($mReview instanceof ModReviews)) return 'Invalid class ModReviews';
    
    	$limit = $modx->getOption('limit',$scriptProperties,false);
    	$start = $modx->getOption('start',$scriptProperties,0);		
    	$sort = $modx->getOption('sort',$scriptProperties,'name');
    	$dir = $modx->getOption('dir',$scriptProperties,'ASC');
    
    	/* build query */
    	$c = $modx->newQuery('modReviews');
    
        if (!empty($query)) {
            $c->where(array(
                'agent:LIKE' => '%'.$query.'%'
            ));
        }
    	
    	if ($limit) $c->limit($limit,$start);
    	    
    	$c->sortby($sort,$dir);
    	$reviews = $modx->getCollection('Review',$c);
    	
    	 
    	return $output."asdf";


    and using chunks bellow
    write it to the web

    [[!codequery]]


    ===========
    but it said

    Invalid class ModReviews
    ===========

    I code only this snippet.
    how to fix it.

    Thanks. [ed. note: nikom2532 last edited this post 13 years, 8 months ago.]
      Web developer at Socket9. Bangkok, Thailand.
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      I think you may be missing a slash after model here:
      'model/modreviews'
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 42544
        • 7 Posts
        Quote from: markh at Jan 22, 2013, 09:24 AM
        I think you may be missing a slash after model here:
        'model/modreviews'

        I already change but still said
        Invalid class ModReviews

        What the requirement code that we need to use, before using ?
         $mReview = $modx->getService('modreviews','ModReviews',
            $modx->getOption('modreviews.core_path',null,
            $modx->getOption('core_path').'components/modreviews/').'model/modreviews',$scriptProperties);
          Web developer at Socket9. Bangkok, Thailand.
          • 3749
          • 24,544 Posts
          Have you generated the class and map files for your class? That's necessary in order to use xPDO with them as you are doing.

          You might find this helpful: http://bobsguides.com/custom-db-tables.html
            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
            • 42544
            • 7 Posts
            Quote from: BobRay at Jan 23, 2013, 01:46 AM
            Have you generated the class and map files for your class? That's necessary in order to use xPDO with them as you are doing.

            You might find this helpful: http://bobsguides.com/custom-db-tables.html

            Hi, Bob,
            and hi all

            From the http://bobsguides.com/custom-db-tables.html
            from Testing your classes topic

            Could you tell me what is 'Quotation' means ?
            Thank you very much

            <?php
            $path = MODX_CORE_PATH . 'components/quotes/';
            $result = $modx->addPackage('quotes',$path . 'model/','bobs_');
            if (! $result) {
              return 'failed to add package';
            } else {
              $output = '<p>added Package</p>';
            }
            
            $quotes = $modx->getCollection('Quotation'); 
            
            $output .= '<p>Total: '. count($quotes) . '</p>';
            
            foreach($quotes as $quote) {
            
                $output .= '<p>Topic: ' . $quote->get('topic');
                $output .= '<br />Quote: ' . $quote->get('quote');
                $output .= '<br />Author: ' . $quote->get('author') . '<br /></p>';
            }
            
            return $output;
            
              Web developer at Socket9. Bangkok, Thailand.
              • 3749
              • 24,544 Posts
              Quotation is just the name of my class (and the xPDO object representing it). The example code was for a database of quotations for this page: http://wordsmatter.softville.com/quotes.html.

              You would use 'modReviews' there and your own path in addPackage().
                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