Ace编辑器在PHP Web应用程序

Ace Editor in PHP Web App

本文关键字:Web 应用程序 PHP 编辑器 Ace      更新时间:2023-09-26

我正在制作一个小的web应用程序,允许用户通过Ace Editor提交html, css和javascript内容。在这个编辑器中,将存储的内容回显到编辑器中就足够了,但是我找不到将用户输入提交到数据库的方法。我可以看到有一个由JavaScript生成的文本区,但我不确定它在做什么,如何得到它,或者如果我应该寻找其他东西完全。

我主要是寻找一个字段,我可以使用php提交到数据库

编辑窗口的内容可以通过会话getValue方法获得。例如,下面是保存文件的标准ACE演示的扩展:

saveFile = function() {
    var contents = env.editor.getSession().getValue();
    $.post("write.php", 
            {contents: contents },
            function() {
                    // add error checking
                    alert('successful save');
            }
    );
};

我将saveFile调用添加到demo.js中已经存在的"Fake Save"中。我用这样的代码替换警报:

// Fake-Save, works from the editor and the command line.
canon.addCommand({
    name: "save",
    bindKey: {
        win: "Ctrl-S",
        mac: "Command-S",
        sender: "editor|cli"
    },
    exec: function() {
        saveFile();
    }
});
php文件只有一行:

$r = file_put_contents("foo.txt", $_POST["contents"]) or die("can't open file");