We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1778
    • 659 Posts
    Hello
    You have to query the Object not the table

    assuming you object is declared more or less like that in your schema:
    <object class="myObject" table="pp_category" extends="xPDOSimpleObject">
            <field key="name" dbtype="varchar" phptype="string" precision="255" null="false" default="" />
           ...
    </object>
    
    


    You query should be :
    $c = $modx->newQuery('myObject') ; // you query the object (the "class=" in your schema) not the table name 
    
    


    it should work then (if you have some records in your table of course)
    Hope this helps
    Cheers
      • 24075
      • 83 Posts
      /www/modx_rev/core/components/pepish/schema/pepish.mysql.schema.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <model package="pepish" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
      	<object class="Category" table="category" extends="xPDOObject">
      		<field key="category_id" dbtype="smallint" precision="4" phptype="integer" null="false" index="pk"  generated="native" />
      		<field key="name" dbtype="varchar" precision="64" phptype="string" null="false" />
      		<field key="name_alt" dbtype="varchar" precision="128" phptype="string" null="false" />
      		<field key="parent_id" dbtype="smallint" precision="4" phptype="integer" null="true" />
      		<field key="view" dbtype="smallint" precision="2" phptype="integer" null="false" default="1" />
      
      		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
      			<column key="category_id" length="" collation="A" null="false" />
      		</index>
      	</object>
      	<object class="Galerie" table="galerie" extends="xPDOObject">
      		<field key="galerie_id" dbtype="int" precision="10" phptype="integer" null="false" index="pk"  generated="native" />
      		<field key="title" dbtype="varchar" precision="48" phptype="string" null="false" />
      		<field key="name_cz" dbtype="varchar" precision="64" phptype="string" null="false" />
      		<field key="name_lat" dbtype="varchar" precision="64" phptype="string" null="false" />
      		<field key="kategorie" dbtype="smallint" precision="4" phptype="integer" null="false" />
      		<field key="kde" dbtype="varchar" precision="64" phptype="string" null="false" />
      		<field key="kdy" dbtype="date" phptype="date" null="true" />
      		<field key="upload_date_time" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
      		<field key="copyright" dbtype="varchar" precision="32" phptype="string" null="false" />
      		<field key="permission" dbtype="smallint" precision="2" phptype="integer" null="false" />
      		<field key="display" dbtype="smallint" precision="2" phptype="integer" null="false" />
      		<field key="short_text" dbtype="mediumtext" phptype="string" null="true" />
      		<field key="picture_name" dbtype="varchar" precision="48" phptype="string" null="true" />
      		<field key="thumbs_name" dbtype="varchar" precision="48" phptype="string" null="true" />
      		<field key="path_large" dbtype="varchar" precision="64" phptype="string" null="true" />
      		<field key="path_thumbs" dbtype="varchar" precision="64" phptype="string" null="true" />
      
      		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
      			<column key="galerie_id" length="" collation="A" null="false" />
      		</index>
      	</object>
      </model>


      /www/modx_rev/core/components/pepish/schema/metadata.mysql.php
      <?php
      
      $xpdo_meta_map = array (
      );


        Petr Püschel, Czech Republic
        <hr>
        http://puschpull.org
        <hr>
        • 1778
        • 659 Posts
        So your query should be :

        if($result){
          $c = $modx->newQuery('Category');
          $c->sortby('name','ASC');
          $pokus = $modx->getCollection('Category',$c);
        }
         echo '$pokus: '.$pokus.'';
          
        foreach ($pokus as $pok) {
           echo $pok->get('name')."\n";
        }
        
          • 24075
          • 83 Posts
          <?php
          $path = MODX_CORE_PATH . 'components/pepish/';
          $result = $modx->addPackage('pepish',$path . 'model/','pp_');
          echo '$result: '.$result.'<br>';
          echo '$path: '.$path.'<br>';
          
          if($result){
            $c = $modx->newQuery('Category');
            $c->sortby('name','ASC');
            $pokus = $modx->getCollection('Category',$c);
          }
           echo '$pokus: '.$pokus.'<br>';
           echo 'Total: '.count($pokus).'<br>';
             
          foreach ($pokus as $pok) {
             echo $pok->get('name')."\n";
          }


          result:
          $result: 1
          $path: /home/www/puschpull.org/www/modx_rev/core/components/pepish/
          $pokus: Array
          Total: 0

          here:
          http://puschpull.org/modx_rev/bob

          somewhere is error
          ?
            Petr Püschel, Czech Republic
            <hr>
            http://puschpull.org
            <hr>
            • 24075
            • 83 Posts
            other files in package:

            /www/modx_rev/core/components/pepish/schema/category.class.php
            <?php
            require_once (dirname(dirname(__FILE__)) . '/category.class.php');
            class Category_mysql extends Category {}


            /www/modx_rev/core/components/pepish/schema/galerie.class.php
            <?php
            class Galerie extends xPDOObject {}


            /www/modx_rev/core/components/pepish/schema/mysql/category.class.php
            <?php
            require_once (dirname(dirname(__FILE__)) . '/category.class.php');
            class Category_mysql extends Category {}


            /www/modx_rev/core/components/pepish/schema/mysql/category.map.inc.php
            <?php
            $xpdo_meta_map['Category']= array (
              'package' => 'pepish',
              'version' => '1.1',
              'table' => 'category',
              'fields' => 
              array (
                'category_id' => NULL,
                'name' => NULL,
                'name_alt' => NULL,
                'parent_id' => NULL,
                'view' => 1,
              ),
              'fieldMeta' => 
              array (
                'category_id' => 
                array (
                  'dbtype' => 'smallint',
                  'precision' => '4',
                  'phptype' => 'integer',
                  'null' => false,
                  'index' => 'pk',
                  'generated' => 'native',
                ),
                'name' => 
                array (
                  'dbtype' => 'varchar',
                  'precision' => '64',
                  'phptype' => 'string',
                  'null' => false,
                ),
                'name_alt' => 
                array (
                  'dbtype' => 'varchar',
                  'precision' => '128',
                  'phptype' => 'string',
                  'null' => false,
                ),
                'parent_id' => 
                array (
                  'dbtype' => 'smallint',
                  'precision' => '4',
                  'phptype' => 'integer',
                  'null' => true,
                ),
                'view' => 
                array (
                  'dbtype' => 'smallint',
                  'precision' => '2',
                  'phptype' => 'integer',
                  'null' => false,
                  'default' => 1,
                ),
              ),
              'indexes' => 
              array (
                'PRIMARY' => 
                array (
                  'alias' => 'PRIMARY',
                  'primary' => true,
                  'unique' => true,
                  'type' => 'BTREE',
                  'columns' => 
                  array (
                    'category_id' => 
                    array (
                      'length' => '',
                      'collation' => 'A',
                      'null' => false,
                    ),
                  ),
                ),
              ),
            );
            


            /www/modx_rev/core/components/pepish/schema/mysql/galerie.class.php
            <?php
            require_once (dirname(dirname(__FILE__)) . '/galerie.class.php');
            class Galerie_mysql extends Galerie {}


            /www/modx_rev/core/components/pepish/schema/mysql/galerie.map.inc.php
            <?php
            $xpdo_meta_map['Galerie']= array (
              'package' => 'pepish',
              'version' => '1.1',
              'table' => 'galerie',
              'fields' => 
              array (
                'galerie_id' => NULL,
                'title' => NULL,
                'name_cz' => NULL,
                'name_lat' => NULL,
                'kategorie' => NULL,
                'kde' => NULL,
                'kdy' => NULL,
                'upload_date_time' => 'CURRENT_TIMESTAMP',
                'copyright' => NULL,
                'permission' => NULL,
                'display' => NULL,
                'short_text' => NULL,
                'picture_name' => NULL,
                'thumbs_name' => NULL,
                'path_large' => NULL,
                'path_thumbs' => NULL,
              ),
              'fieldMeta' => 
              array (
                'galerie_id' => 
                array (
                  'dbtype' => 'int',
                  'precision' => '10',
                  'phptype' => 'integer',
                  'null' => false,
                  'index' => 'pk',
                  'generated' => 'native',
                ),
                'title' => 
                array (
                  'dbtype' => 'varchar',
                  'precision' => '48',
                  'phptype' => 'string',
                  'null' => false,
                ),
                'name_cz' => 
                array (
                  'dbtype' => 'varchar',
                  'precision' => '64',
                  'phptype' => 'string',
                  'null' => false,
                ),
                'name_lat' => 
                array (
                  'dbtype' => 'varchar',
                  'precision' => '64',
                  'phptype' => 'string',
                  'null' => false,
                ),
                'kategorie' => 
                array (
                  'dbtype' => 'smallint',
                  'precision' => '4',
                  'phptype' => 'integer',
                  'null' => false,
                ),
                'kde' => 
                array (
                  'dbtype' => 'varchar',
                  'precision' => '64',
                  'phptype' => 'string',
                  'null' => false,
                ),
                'kdy' => 
                array (
                  'dbtype' => 'date',
                  'phptype' => 'date',
                  'null' => true,
                ),
                'upload_date_time' => 
                array (
                  'dbtype' => 'timestamp',
                  'phptype' => 'timestamp',
                  'null' => false,
                  'default' => 'CURRENT_TIMESTAMP',
                ),
                'copyright' => 
                array (
                  'dbtype' => 'varchar',
                  'precision' => '32',
                  'phptype' => 'string',
                  'null' => false,
                ),
                'permission' => 
                array (
                  'dbtype' => 'smallint',
                  'precision' => '2',
                  'phptype' => 'integer',
                  'null' => false,
                ),
                'display' => 
                array (
                  'dbtype' => 'smallint',
                  'precision' => '2',
                  'phptype' => 'integer',
                  'null' => false,
                ),
                'short_text' => 
                array (
                  'dbtype' => 'mediumtext',
                  'phptype' => 'string',
                  'null' => true,
                ),
                'picture_name' => 
                array (
                  'dbtype' => 'varchar',
                  'precision' => '48',
                  'phptype' => 'string',
                  'null' => true,
                ),
                'thumbs_name' => 
                array (
                  'dbtype' => 'varchar',
                  'precision' => '48',
                  'phptype' => 'string',
                  'null' => true,
                ),
                'path_large' => 
                array (
                  'dbtype' => 'varchar',
                  'precision' => '64',
                  'phptype' => 'string',
                  'null' => true,
                ),
                'path_thumbs' => 
                array (
                  'dbtype' => 'varchar',
                  'precision' => '64',
                  'phptype' => 'string',
                  'null' => true,
                ),
              ),
              'indexes' => 
              array (
                'PRIMARY' => 
                array (
                  'alias' => 'PRIMARY',
                  'primary' => true,
                  'unique' => true,
                  'type' => 'BTREE',
                  'columns' => 
                  array (
                    'galerie_id' => 
                    array (
                      'length' => '',
                      'collation' => 'A',
                      'null' => false,
                    ),
                  ),
                ),
              ),
            );
            


              Petr Püschel, Czech Republic
              <hr>
              http://puschpull.org
              <hr>
              • 24075
              • 83 Posts
              Hurray!!

              Solved! (in the meantime)

              Problem is in table structure "pp_category"
              With table "pp_galerie" is this OK

              <?php
              $path = MODX_CORE_PATH . 'components/pepish/';
              $result = $modx->addPackage('pepish',$path . 'model/','pp_');
              echo '$result: '.$result.'<br>';
              echo '$path: '.$path.'<br>';
              
              if($result){
                $c = $modx->newQuery('Galerie');
                $c->where(array(
                  'Galerie.name_cz' => 'Šidélko brvonohé',
                  'Galerie.kde' => 'Průhonice',
              ));
                $c->sortby('galerie_id','ASC');
                $pokus = $modx->getCollection('Galerie',$c);
              }
               echo '$pokus: '.$pokus.'<br>';
               echo 'Total: '.count($pokus).'<br>';
                 
              foreach ($pokus as $pok) {
                echo $pok->get('galerie_id')."\n";
                echo $pok->get('name_cz')."\n";
                echo $pok->get('name_lat')."\n";
                echo $pok->get('kde').'<br>'."\n";
              }


              and result on screen:
              $result: 1
              $path: /home/www/puschpull.org/www/modx_rev/core/components/pepish/
              $pokus: Array
              Total: 7
              34 Šidélko brvonohé (Platycnemis pennipes) Průhonice
              35 Šidélko brvonohé (Platycnemis pennipes) Průhonice
              36 Šidélko brvonohé (Platycnemis pennipes) Průhonice
              37 Šidélko brvonohé (Platycnemis pennipes) Průhonice
              38 Šidélko brvonohé (Platycnemis pennipes) Průhonice
              39 Šidélko brvonohé (Platycnemis pennipes) Průhonice
              43 Šidélko brvonohé (Platycnemis pennipes) Průhonice


              the same script with table "pp_category" work not
              <?php
              $path = MODX_CORE_PATH . 'components/pepish/';
              $result = $modx->addPackage('pepish',$path . 'model/','pp_');
              echo '$result: '.$result.'<br>';
              echo '$path: '.$path.'<br>';
              
              if($result){
                $c = $modx->newQuery('Category');
                $c->sortby('category_id','ASC');
                $pokus = $modx->getCollection('Category',$c);
              }
               echo '$pokus: '.$pokus.'<br>';
               echo 'Total: '.count($pokus).'<br>';
                 
              foreach ($pokus as $pok) {
                 echo $pok->get('category_id')."\n";
              }


              result on screen:
              $result: 1
              $path: /home/www/puschpull.org/www/modx_rev/core/components/pepish/
              $pokus: Array
              Total: 0


              Online result is here:
              http://puschpull.org/modx_rev/bob-galerie
              and here:
              http://puschpull.org/modx_rev/bob-category
                Petr Püschel, Czech Republic
                <hr>
                http://puschpull.org
                <hr>
                • 1778
                • 659 Posts
                Glad you have it to work ^_^
                Cheers
                  • 24075
                  • 83 Posts
                  And now second question:
                  What formated data output (first simple like this - simple table):
                  http://puschpull.org/modx_rev/frameworks/frameworks1

                  getCollectionGraph ?

                  I need some Examples
                  Thanks!
                  :-)
                    Petr Püschel, Czech Republic
                    <hr>
                    http://puschpull.org
                    <hr>
                    • 1778
                    • 659 Posts
                    Hello

                    You can output directly the table you want doing something like that,
                    $path = MODX_CORE_PATH . 'components/pepish/';
                    $result = $modx->addPackage('pepish',$path . 'model/','pp_');
                    echo '$result: '.$result.'';
                    echo '$path: '.$path.'';
                     
                    if($result){
                      $c = $modx->newQuery('Galerie');
                      $c->where(array(
                        'Galerie.name_cz' => 'Šidélko brvonohé',
                        'Galerie.kde' => 'Průhonice',
                    ));
                      $c->sortby('galerie_id','ASC');
                      $pokus = $modx->getCollection('Galerie',$c);
                    }
                    // echo '$pokus: '.$pokus.'';
                    // echo 'Total: '.count($pokus).'';
                    
                    
                    $galid= $pok->get('galerie_id');
                    $namecz =   $pok->get('name_cz');
                    $namealt = $pok->get('name_lat');
                    $kde = $pok->get('kde');
                    
                    $output = ''; // initialize the output
                    
                    
                    if(count($pokus)>0){ // if there is something to output
                        //starts the table
                        $ouptut .= '<table><tr>
                            <th>id</th>
                            <th>name</th>
                            <th>name_alt</th>
                            <th>parent_id</th>
                            <th>view</th>
                            </tr>';
                        foreach ($pokus as $pok) {
                            // write each line of the table 
                            $output .= '<tr>
                                        <td>'.$galid.'</td>
                                        <td>'.$namecz.'</td>
                                        <td>'.$namealt.'</td>
                                        <td>'.$kde.'</td></tr>'; 
                        }
                        return $output.'</table>'; // close the table and return it
                    }
                    

                    I did it a bit fast and did not test but it should give you the way to achieve what you want.

                    BTW a snippet should not 'echo' something but return something...
                    Hope this helps
                    Cheers
                      • 24075
                      • 83 Posts
                      anso:
                      Thanks you very much!

                      Now I be experiment with this sample code
                      :-)
                        Petr Püschel, Czech Republic
                        <hr>
                        http://puschpull.org
                        <hr>