链接
官方文档
自用修改版
HTML
<textarea
name="article_content"
id="editor"
style="width:100%;height:500px;"
>{$row[article_content]}</textarea>
<script src="/Public/kindeditor/kindeditor-all-min.js"></script>
<script src="/Public/kindeditor/lang/zh-CN.js"></script>
<script>
var editorItems = [
'source'
, '|'
, 'undo'
, 'redo'
, '|'
, 'plainpaste'
, 'wordpaste'
, 'clearhtml'
, '|'
, 'justifyleft'
, 'justifycenter'
, 'justifyright'
, '|'
, 'fontsize'
, 'forecolor'
, 'hilitecolor'
, 'bold'
, 'italic'
, 'underline'
, 'strikethrough'
, 'removeformat'
, '|'
, 'image'
, 'insertfile'
, '|'
, 'link'
, 'unlink'
, '|'
, 'preview'
, 'fullscreen'
]
KindEditor.ready(function (K) {
window.editor = K.create('#editor', {
// , uploadJson: '/Public/kindeditor/php/upload_json.php'
items: editorItems
});
})
//保存时获取更新后的数据
form.on('submit(*)', function (e) {
var data = e.field
editor.sync()
data.article_content = $('#editor').val()
if (!data.article_content) {
layer.msg('文章内容不允许为空', { icon: 5 })
return false
}
console.log(data)
$.post('__CONTROLLER__/store', data, function (res) {
console.log(res)
if (res.status == 1) {
layer.msg('保存成功', {
icon: 6
, time: 2000
}, function () {
closeParentLayer()
})
} else {
layer.msg(res.error, { icon: 5 })
}
})
return false
})
</script>
php
// /Root/Controller/BaseController.class.php
function store(){
$data=\in_array(CONTROLLER_NAME,['Site','Article'])?I('post.',[],''):I('post.');
$this->ajaxReturn(D(CONTROLLER_NAME)->store($data));
}