0

我尝试使用教程将我的一个插件编写到 modx 并陷入构建查询的部分

那是我的片段:

$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;

使用该输出:

Array ( [id] => 1 [name] => Правда Музыка ) F:\Yandex\Sites\modx\musiclabel\core\components\musiclabel\model\musiclabel\->MusicLabel->SELECT `` FROM AS `MusicLabel` 

所以当 getCollection 不起作用时我无法理解

这是我的文件:

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 安装在“D:\www\modx-2.7.3-pl”中,两个系统设置是:

musiclabel.assets_url = ml.modx.local/assets/components/musiclabel/

musiclabel.core_path = F:\Yandex\Sites\modx\musiclabel\core\components\musiclabel\

4

0 回答 0