We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37464
    • 16 Posts
    The object is created and managed using MIGX. This is the schema:
    <?xml version="1.0" encoding="UTF-8"?>
    	<model package="mik_organization" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
    		<object class="MikTeam" table="mik_teams" extends="xPDOSimpleObject">
    			<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
    			<field key="admin_url" dbtype="varchar" precision="350" phptype="string" null="false" default=""/>
    			<field key="team_type_id" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" default="0" />
    		</object> 
        </object>
    </model>


    How do I get the value of 'admin_url' from 1 instance of a MikTeam object based on the value of 'name'?

    This is what I've tried:

    Snippet:
    <?php
    $teamurl = $modx->getObject('MikTeam', array('name'=>'f05'));
    return $teamurl->get('admin_url');


    never returns anything and the error log says
    [2015-07-01 10:12:34] (ERROR @ /index.php) Could not load class: MikTeam from mysql.mikteam.
    [2015-07-01 10:12:34] (ERROR @ /index.php) MikTeam::load() is not a valid static method.



    • What am I doing wrong?
    • Is $modx->getObject the best way to do this?

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

    • discuss.answer
      • 4172
      • 5,888 Posts
      you need to add the package before you can use its classes:

      $prefix = null;
      $packageName = 'mik_organization';
      $packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
      $modelpath = $packagepath . 'model/';
      if (is_dir($modelpath)) {
          $modx->addPackage($packageName, $modelpath, $prefix);
      }
      if ($teamurl = $modx->getObject('MikTeam', array('name'=>'f05'))){
          return $teamurl->get('admin_url');
      }
      return 'not found';
      
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!