1

我尝试过以下查询并使用了 Cake 的核心 XML 类,但我得到 String could not be parsed as XML 错误...

$output = $this->Job->query("
            SELECT job.id, job.title, organisation.name, jobsboard.name
            FROM job
            LEFT JOIN portfolio_job_category pjc ON pjc.job_id = job.id
            LEFT JOIN category c ON c.id = pjc.category_id
            LEFT JOIN organisation ON organisation.id = job.organisation_id
            LEFT JOIN portfolio jobsboard ON jobsboard.id = pjc.portfolio_id
            WHERE job.end_date >= DATE( NOW( ) ) 
            AND pjc.portfolio_id = $portfolio
            ORDER BY c.id DESC
            ");
$jobs['jobs_feed'] = $output;
$jobs = Xml::fromArray($jobs);
$jobs = $jobs->asXML();

以下是模型自定义查询的数组输出。

Array
(
    [0] => Array
        (
            [job] => Array
                (
                    [id] => 38459
                    [title] => UTS: Engineering Research Scholarships in Petroleum Remediation
                )

            [organisation] => Array
                (
                    [name] => University of Technology Sydney
                )

            [jobsboard] => Array
                (
                    [name] => Research Jobs
                )

        )

    [1] => Array
        (
            [job] => Array
                (
                    [id] => 44144
                    [title] => Associate Lecturer - Clinical Exercise Physiology
                )

            [organisation] => Array
                (
                    [name] => James Cook University
                )

            [jobsboard] => Array
                (
                    [name] => Research Jobs
                )

        )
)

我能做些什么来解决这个问题吗?

4

1 回答 1

0

xml 需要一个根节点:

改变:

$jobs = Xml::fromArray($jobs);

至:

$jobs = Xml::fromArray(array('jobs' => $jobs));
于 2012-07-27T08:08:18.553 回答