CodeIgniter - 将WYSIWYG编辑器的HTML内容保存在数据库中以供日后使用
This may be a longshot but I am struggling to find help online and I am genuinely lost ..
I am building a CodeIgniter Web App where users can sign in, and create email templates, then send them to contacts..
I am using the Trumbowyg Editor for creating the email templates which I have found quite good and flexible, i have pre-made templates the users can select and edit if they please..
what i want however is for a user to create their own template, or make edits to an existing one, and save it to be able to come back at a later date.. I think it is possible to save it to my database, I have a template table setup correctly with foreign keys etc and i have the 'templatestyle' field type set as 'blob', in order to save the content here..
I am able to get the contents of the wysiwyg as when I test out this code of clicking the saveContent button I get the current content in the console.log;
$("#saveContent").click(function(){
console.log($("#trumbowyg-demo").html());
});
so what i need is this content saved to my database template table which has 3 columns; 'an id, a foreign key id for the user, and the template style..
I realise there is a lot in here and any code provided in order to help me set this up to save my database will be massively appreciated
thanks in advance!
</div>
这可能是一个远景,但我很难在网上找到帮助而且我真的迷失了...... p>
我正在构建一个CodeIgniter Web App,用户可以在其中登录并创建电子邮件模板,然后将其发送给联系人.. p>
我正在使用 Trumbowyg Editor 用于创建我发现非常好且灵活的电子邮件模板,我预先制作了模板 用户可以随意选择和编辑.. p>
我想要的是用户创建自己的模板,或者对现有模板进行编辑,并将其保存为能够 以后再回来..我认为可以将它保存到我的数据库中,我有一个模板表设置正确使用外键等,我将'templatestyle'字段类型设置为'blob',以便 在这里保存内容.. p>
当我测试这个点击代码时,我能够获得所见即所得的内容 saveContent按钮我在console.log中获取当前内容; p>
p>
$( “#saveContent”)点击(函数(){ console.log($( “#trumbowyg-演示”)的html()); \ N})。 ; code> pre> div> div>所以我需要的是这个内容保存到我的数据库模板表中 有3列; '一个id,一个用户的外键ID,以及模板样式.. p>
我意识到这里有很多东西,并提供任何代码以帮助我将其设置为 保存我的数据库将受到大力赞赏 p>
提前感谢! p> div>
Generally speaking you just have to send a simple post with one var to a controller method that receives the post var and inputs it in the database.
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;
}
}