PHP Web App 中的王牌编辑器 [英] Ace Editor in PHP Web App
问题描述
我正在制作一个小型网络应用程序,允许用户通过 Ace Editor 提交 html、css 和 javascript 内容.在这个编辑器中,将存储的内容回显到编辑器中就足够了,但是我无论如何都找不到将用户输入提交到数据库的方法.我可以看到 JavaScript 生成了一个 textarea,但是我不确定它在做什么,如何找到它,或者我是否应该完全寻找其他东西.
I am making a small web app that allows users to submit html, css and javascript content via Ace Editor. In this editor, echoing stored content into the editor is simply enough however I cannot find anyway to submit a users input to the database. I can see there is a textarea generated by the JavaScript however I'm not exactly sure what it is doing, how to get to it or if I should be looking for something else entirely.
我主要是在寻找一个字段或可用于将 php 提交到数据库中的内容.
I'm primarily looking for a field or something that I can use to have php submit into the db.
推荐答案
编辑窗口的内容可通过 session getValue 方法获得.例如,这里是用于保存文件的标准 ACE 演示的扩展:
The contents of the edit window are available with the session getValue method. For example, here is an extension to the standard ACE demo for save file:
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".我用这样的代码替换警报:
I added the saveFile call to the already existing "Fake Save" that is in demo.js. I replace the alert with code like this:
// 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 文件只有一行:
The php file is just one line:
$r = file_put_contents("foo.txt", $_POST["contents"]) or die("can't open file");
这篇关于PHP Web App 中的王牌编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!