PHP 调用成员函数 saveXML() 在 AJAX POST 上的非对象上



谁能看到我的代码出了什么问题?我得到的错误如下:

致命错误:在第 35 行的/path/to/php/file.php 中的非对象上调用成员函数 saveXML()

基本上,我只是尝试更新一个XML节点值,该值根据"可用性"标签中设置的值更改UI。

===================

更新 ===

======================

XML文件现在没有被("可用性")标签内("状态")节点的新值覆盖,我做错了什么吗?!

====

=====================================================

XML 结构

<?xml version="1.0" encoding="UTF-8"?>
<WORK>
    <AVAILABILITY>
        <STATUS>0</STATUS> // Not being changed?!
    </AVAILABILITY>
    <SLIDE>
        <ID>YY001</ID>
        <TITLE>YourEdentity</TITLE>
        <LINK>http://youredentity.campearce.co.uk</LINK>
        <THUMB>your_ed.png</THUMB>
        <CAPTION>This is YourEdentity</CAPTION>
    </SLIDE>
</WORK>

PHP 脚本:

<?php
$url = "../content/slides.xml";
$xml = simplexml_load_file($url);
if(!file_exists($url))
{
echo "Unable to locate file";
}
else
{
$root = $xml->WORK;
$slides = $root->SLIDE;
if(isset($_POST['action']) && !empty($_POST['action']))
{
    $action = $_POST['action'];
    switch($action)
    {
        case 'deleteslide' : delete_slide(); break;
        case 'createslide' : create_slide(); break;
        case 'changeavail' : change_avail($root, $_POST['status'], $xml, $url); break;
    }   
}
}
function change_avail($root_node, $status, $xml, $location){
$availability_node = $root_node->AVAILABILITY;
$status_node[0] = $availability_node->STATUS;
parse_str($status, $statustr);
$status_node[0] = $statustr;
file_put_contents($location, $xml->asXML());
echo $xml->asXML();
}
function save_toxml($xml, $location)
{
$fp = fopen($location, 'w');
fwrite($fp, $xml->asXML());
fclose($fp);
echo $xml->asXML();
}
?>

在函数change_avail中,您没有变量$xml。传输此变量:

function change_avail($root_node, $status, DOMDocument $xml)

最新更新