We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30524
    • 22 Posts
    Hello,

    I’m pretty new to modx.

    But I tried to get used to the api and coding snippets.

    I looked through some snippet code and I found it really interesting that a lot of developer rather use sql-statement than the modxapi.
    My understanding is that if you use a cms/framework always try to call the core function that already there, before create new ways of doing thinks.

    Can someone help me with this ?

    Example:

    getting document data with a special id.

    $sql = "SELECT "
    
    	.$site_content.".id"
    
    	.",".$site_content.".pagetitle"
    
    	.",".$site_content.".longtitle"	
    
    	.",".$site_content.".menutitle"
    
    	.",".$site_content.".description"
    	.",".$site_content.".menuindex"		
    
    	." FROM "
    
    	.$site_content
    
    	." WHERE"
    
    	." (".$parentWhere_str.")"		
    
    	
    
    	." ORDER BY ".$site_content.".menuindex"	
    
    	." ASC";
    
    $rs = $modx->dbQuery($sql);	
    
    $rs_count = $modx->recordCount($rs);
    
    
    kalendar snippet code

    VS

    (...)
    $content = $modx->getDocument(1,'pagetitle...','1');
    (...)
    


    matic
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      It is definitely "best practice" to use the MODx API. But it takes time to learn what it offers and how to use it; many developers are on a deadline and just need a working function NOW.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 37099
        • 338 Posts
        If you have the time, why is it best practice?

          • 28042 ☆ A M B ☆
          • 24,524 Posts
          I think the arcane philosophy behind the choice of coding practices is best answered by someone like OpenGeek or Splittingred. For myself, it just feels better.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 22303 MODX Staff
            • 10,725 Posts
            Making it portable to other database engines, making it able to survive upgrades or changes to a database table, and other less important reasons.