We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43775
    • 1 Posts
    Hello, request your assistance, please help me.
    MODX Revolution 2.2.7-pl (traditional)

    In chunk call snippet [[!getNewsContentPage]]
    In snippet call DBAPI function: $temp = $modx->db->query('Select * From `modx_site_content` WHERE template=11');

    server return Fatal error: Call to a member function query() on a non-object in W:\domains\bpcby\core\cache\includes\elements\modsnippet\38.include.cache.php on line 7


    38.include.cache.php:
    <?php
    function elements_modsnippet_38($scriptProperties= array()) {
    global $modx;
    if (is_array($scriptProperties)) {
    extract($scriptProperties, EXTR_SKIP);
    }
    $temp = $modx->db->query('Select * From `modx_site_content` WHERE template=11');
    while($row = $modx->db->getRow($temp))
    {
      if($row['id'] == $rid)
      {
        $row = $modx->db->getRow($temp);
        $pt2 = $row['pagetitle'];
        if(isset($pt2)){$pt2 .= ">>";}
        $rid2 = $row['id'];
        break;
      }
      $pt1 = "<<".$row['pagetitle'];
      $rid1 = $row['id'];
    }
    $rid1 = "[[~".$rid1."]]";
    $rid2 = "[[~".$rid2."]]";
    $modx->setPlaceholder('PageTitle1',$pt1);
    $modx->setPlaceholder('fid',$rid1);
    $modx->setPlaceholder('PageTitle2',$pt2);
    $modx->setPlaceholder('sid',$rid2);
    $output = $modx->parseChunk('news_content_page', $modx->placeholders);
    return $output;
    }
    
    
    



    And other DBAPI function connect
    delete, disconnect, escape, getAffectedRows, getColumn, getColumnNames, getHTMLGrid, getInsertId, getRecordCount, getRow, getTableMetaData, getValue, getXML, insert, makeArray, prepareDate, query, select, update
    return fatal error.
    [ed. note: sokolby last edited this post 13 years, 4 months ago.]
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      The DBAPI is ancient and only exists in Evolution or Revolution 2.0. Instead of using the DBAPI, you should use the xPDO APIs.

      Rewriting your snippet would look something like this (untested though):

      $temp = $modx->getCollection('modResource', array('template' => 11));
      foreach ($temp as $resource) {
        if ($resource->get('id') == $rid) {
          $row = $resource->toArray();
          $pt2 = $row['pagetitle'];
          if (isset($pt2)) { $pt2 .= ">>"; } // note that isset($pt2) is always true.. what's the point here??
          $rid2 = $row['id'];
          break;
        }
        $pt1 = "<<" . $resource->get('pagetitle');
        $rid1 = $resource->get('id');
      }
      
      $rid1 = "[[~".$rid1."]]";
      $rid2 = "[[~".$rid2."]]";
      $placeholders = array(
         'PageTitle1' => $pt1,
         'fid' => $rid1,
         'PageTitle2' => $pt2,
         'sid' => $rid2
      );
      $output = $modx->getChunk('news_content_page', $placeholders);
      return $output;


      Some relevant reading:

      http://rtfm.modx.com/display/xPDO20/Retrieving+Objects
      http://rtfm.modx.com/display/xPDO20/xPDO.getCollection
      http://rtfm.modx.com/display/xPDO20/xPDO.getObject
      http://rtfm.modx.com/display/xPDO20/xPDO.newQuery
      http://rtfm.modx.com/display/xPDO20/xPDOQuery
        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.