I try to write my one plugin to modx with that tutorial and get stuck on section building the query
That is my snippet:
$defaultDoodlesCorePath = $modx->getOption('core_path').'components/musiclabel/';
$doodlesCorePath = $modx->getOption('musiclabel.core_path',null,$defaultDoodlesCorePath);
$dood = $modx->getService('musiclabel','MusicLabel',$doodlesCorePath.'model'.DIRECTORY_SEPARATOR.'musiclabel'.DIRECTORY_SEPARATOR,$scriptProperties);
$c = $modx->newQuery('MusicLabel');
$c->prepare();
$leadersql = "SELECT * FROM `modx_musiclabels` WHERE 1";
$q= $modx->query($leadersql);
while ($row = $q->fetch(PDO::FETCH_ASSOC)) {
print_r($row);
}
$output = $doodlesCorePath.'model'.DIRECTORY_SEPARATOR.'musiclabel'.DIRECTORY_SEPARATOR.'->'.get_class($dood) . '->'. $c->toSQL();
return $output;
with that output:
Array ( [id] => 1 [name] => Правда Музыка ) F:\Yandex\Sites\modx\musiclabel\core\components\musiclabel\model\musiclabel\->MusicLabel->SELECT `` FROM AS `MusicLabel`
So I can't understand while getCollection doesn't work
Here's my files:
F:\Yandex\Sites\modx\musiclabel\core\components\musiclabel\model\muscilabel\musiclabel.class.php
<?php
class MusicLabel {
public $modx;
public $config = array();
public function __construct(modX &$modx,array $config = array()) {
$this->modx =& $modx;
$basePath = $this->modx->getOption('musiclabel.core_path',$config,$this->modx->getOption('core_path').'components'.DIRECTORY_SEPARATOR.'musiclabel'.DIRECTORY_SEPARATOR);
$assetsUrl = $this->modx->getOption('musiclabel.assets_url',$config,$this->modx->getOption('assets_url').'components'.DIRECTORY_SEPARATOR.'musiclabel'.DIRECTORY_SEPARATOR);
$this->config = array_merge(array(
'basePath' => $basePath,
'corePath' => $basePath,
'modelPath' => $basePath.'model/',
'processorsPath' => $basePath.'processors/',
'templatesPath' => $basePath.'templates/',
'chunksPath' => $basePath.'elements/chunks/',
'jsUrl' => $assetsUrl.'js/',
'cssUrl' => $assetsUrl.'css/',
'assetsUrl' => $assetsUrl,
'connectorUrl' => $assetsUrl.'connector.php',
),$config);
$this->modx->addPackage('musiclabel',$this->config['modelPath']);
}
}
F:\Yandex\Sites\modx\musiclabel\core\components\musiclabel\model\schema\musiclabel.mysql.schema.xml
<?xml version="1.0" encoding="UTF-8"?>
<model package="musiclabel" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.0">
<object class="MusicLabel" table="musiclabels" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
</object>
<object class="Artist" table="artists" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="description" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="musiclabel" dbtype="int" precision="11" phptype="integer" null="true" />
<aggregate alias="MusicLabel" class="MusicLabel" local="musiclabel" foreign="id" cardinality="one" owner="foreign" />
</object>
<object class="Album" table="albums" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="description" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="artist" dbtype="int" precision="11" phptype="integer" null="true" />
<aggregate alias="Artist" class="Artist" local="artist" foreign="id" cardinality="one" owner="foreign" />
</object>
<object class="YoutubeClip" table="youtubeclips" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="description" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="artist" dbtype="int" precision="11" phptype="integer" null="true" />
<aggregate alias="Artist" class="Artist" local="artist" foreign="id" cardinality="one" owner="foreign" />
</object>
<object class="YoutubeLive" table="youtubelives" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="description" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="artist" dbtype="int" precision="11" phptype="integer" null="true" />
<aggregate alias="Artist" class="Artist" local="artist" foreign="id" cardinality="one" owner="foreign" />
</object>
</model>
Modx is installed in "D:\www\modx-2.7.3-pl" and two System Settings are:
musiclabel.assets_url = ml.modx.local/assets/components/musiclabel/
musiclabel.core_path = F:\Yandex\Sites\modx\musiclabel\core\components\musiclabel\