CodeIgniter - 在数据库中保存 HTML 所见即所得编辑器的内容以供日后使用
CodeIgniter - Save HTML content of WYSIWYG editor in a database to be used at a later date
这可能是一个远景,但我正在努力寻找在线帮助,我真的迷路了..
我正在构建一个 CodeIgniter Web 应用程序,用户可以在其中登录并创建电子邮件模板,然后将它们发送给联系人..
我正在使用 Trumbowyg Editor 创建电子邮件模板,我发现它非常好且灵活,我有预制模板,用户可以 select 并根据需要进行编辑..
然而,我想要的是让用户创建自己的模板,或对现有模板进行编辑,然后保存它以便日后返回。我认为可以保存它对于我的数据库,我有一个模板 table 使用外键等正确设置,并且我将 'templatestyle' 字段类型设置为 'blob',以便在此处保存内容..
我能够获取所见即所得的内容,因为当我测试单击 saveContent 按钮的这段代码时,我在 console.log;
中获取了当前内容
$("#saveContent").click(function(){
console.log($("#trumbowyg-demo").html());
});
所以我需要的是将此内容保存到我的数据库模板 table 中,该模板有 3 列; '一个id,用户的外键id和模板样式..
我知道这里有很多内容,非常感谢提供任何代码来帮助我设置它以保存我的数据库
提前致谢!
一般来说,您只需将一个简单的 post 和一个变量发送到接收 post 变量并将其输入数据库的控制器方法。
JS:
$("#saveContent").click(function () {
var content = $("#trumbowyg-demo").html();
$.ajax({
type: 'POST',
url: '/somecontroller/add',
data: {
content: content
},
dataType: 'json',
success: function (data) {
if (data.status == 'error') {
alert('An error occured: ' + data.msg);
} else {
alert('Success: ' + data.msg)
}
}
});
});
PHP:
class Somecontroller extends CI_Controller {
public function add() {
$content = $this->input->post('content');
if (empty($content)) {
echo json_encode(array('status' => 'error', 'msg' => 'Content field cannot be empty!'));
exit;
}
// db functions should be move to a model
// probably would be a good idea to filter $content somehow
// all the db insert does is escape
$this->db->insert('sometable', array('somefield' => $content));
echo json_encode(array('status' => 'success', 'msg' => 'Item added with id: ' . $this->db->insert_id()));
exit;
}
}
这可能是一个远景,但我正在努力寻找在线帮助,我真的迷路了..
我正在构建一个 CodeIgniter Web 应用程序,用户可以在其中登录并创建电子邮件模板,然后将它们发送给联系人..
我正在使用 Trumbowyg Editor 创建电子邮件模板,我发现它非常好且灵活,我有预制模板,用户可以 select 并根据需要进行编辑..
然而,我想要的是让用户创建自己的模板,或对现有模板进行编辑,然后保存它以便日后返回。我认为可以保存它对于我的数据库,我有一个模板 table 使用外键等正确设置,并且我将 'templatestyle' 字段类型设置为 'blob',以便在此处保存内容..
我能够获取所见即所得的内容,因为当我测试单击 saveContent 按钮的这段代码时,我在 console.log;
中获取了当前内容$("#saveContent").click(function(){
console.log($("#trumbowyg-demo").html());
});
所以我需要的是将此内容保存到我的数据库模板 table 中,该模板有 3 列; '一个id,用户的外键id和模板样式..
我知道这里有很多内容,非常感谢提供任何代码来帮助我设置它以保存我的数据库
提前致谢!
一般来说,您只需将一个简单的 post 和一个变量发送到接收 post 变量并将其输入数据库的控制器方法。
JS:
$("#saveContent").click(function () {
var content = $("#trumbowyg-demo").html();
$.ajax({
type: 'POST',
url: '/somecontroller/add',
data: {
content: content
},
dataType: 'json',
success: function (data) {
if (data.status == 'error') {
alert('An error occured: ' + data.msg);
} else {
alert('Success: ' + data.msg)
}
}
});
});
PHP:
class Somecontroller extends CI_Controller {
public function add() {
$content = $this->input->post('content');
if (empty($content)) {
echo json_encode(array('status' => 'error', 'msg' => 'Content field cannot be empty!'));
exit;
}
// db functions should be move to a model
// probably would be a good idea to filter $content somehow
// all the db insert does is escape
$this->db->insert('sometable', array('somefield' => $content));
echo json_encode(array('status' => 'success', 'msg' => 'Item added with id: ' . $this->db->insert_id()));
exit;
}
}