We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    I’m tapping into xPDO for the first time (woot!)... wondering if someone can point me to the page(s) where the valid operators are listed?

    $my_xpdo= new xPDO('mysql:host=localhost;dbname=mydb','myuser','mypassword','');
    $my_xpdo->addPackage('edf','/Users/everett/Sites/EDF-modx/html/core/components/edf/model/');
    
    $resources = $my_xpdo->getCollection('MyTable', array(  
       'description' => 'search for this',  
    ));
    
    $tpl = 'myTpl';
    foreach ($resources as $r) {  
        $resourceArray = $r->toArray();  
        $resourceArray['cls'] = $rowCls;  
        $output .= $modx->getChunk($tpl,$resourceArray);  
    }
    
    return $output;



    For example, I want to return all rows from my table where the ’description’ contains ’search for this’. Something like "SELECT * FROM my_table WHERE description LIKE ’%search for this%’;

    I stumbled across some of these before, but now I can’t find them... you know... stuff like " ’description:>’ => ’5’," for greater than, etc.

    Thanks.
      • 28215
      • 4,149 Posts
      $resources = $xpdo->getCollection('MyTable', array(  
         'description:LIKE' => '%search for this%',  
      ));

        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        Thanks Shaun. It looks like the "%" were accidentally omitted from the docs here:
        http://rtfm.modx.com//display/xPDO20/xPDOQuery

        Shouldn’t those instances of "LIKE" include values with the "%"? And... if I wanted to use that to build a search form, is there any built-in API method that could sanitize my input string (e.g. by escaping %)?

        Thanks!