我已经在我的codeigniter版本中安装了TinyMCE,并且还包含了镜像管理器。
在镜像管理器插件(保存在public/assets文件夹中)中有一个php配置文件,它定义了镜像和文件路径常量。
define('DIR_IMAGES', 'images/path/here'); etc我的问题是,我需要的路径是动态的,取决于数据库中的一些数据,例如template_name,但我不知道如何在配置文件中包含正确的文件,以便我可以查看动态信息。
因此,如果用户保存了template_name,那么我需要的路径是
define('DIR_IMAGES', $template_name.'images/path/here');我还在core/MY_Controller.php中的一个常量中定义了template_name,因此如果我可以访问该变量,这将比查询数据库更容易,但这两种方法都可以工作。
有人能帮我一下吗,非常感谢!
发布于 2012-12-13 10:40:30
我只定制了tinymce镜像,但没有使用TinyMCE镜像管理器。
但我使用下面的链接中的教程。
How-to implement a custom file browser
<!-- Start tinymce custom -->
<script type="text/javascript">
tinyMCE.init({
<!--
your tiny mce init here
--->
<!-- custom file browser callback -->
file_browser_callback : 'myFileBrowser',
});
function myFileBrowser (field_name, url, type, win) {
// this is your dynamic image path
var cmsURL = "<?php echo base_url() ?>admin/media/select_image"; <== you can set as you wish
if (cmsURL.indexOf("?") < 0) {
//add the type as the only query parameter
cmsURL = cmsURL + "?type=" + type;
}
else {
//add the type as an additional query parameter
// (PHP session ID is now included if there is one at all)
cmsURL = cmsURL + "&type=" + type;
}
tinyMCE.activeEditor.windowManager.open({
file : cmsURL
,width : 600
,height : 600
,resizable : "yes"
,inline : "yes"
,close_previous : "yes"
,popup_css : true // Disable TinyMCE's default popup CSS
}, {
window : win,
input : field_name
});
return false;
}
</script>发布于 2018-06-02 13:41:35
将"data-“属性添加到tinymce元素,并从那里回显您想要的url。然后在tinymce activeEditor中,访问该数据属性值。
Textarea
<textarea name="description" class="tinymceDescription" data-uploadLink="<?php echo DIR_IMAGES; ?>" ></textarea>TinyMce
tinymce.init({
// other settings here
//either use this if you are uploading automatically.
images_upload_url: $(tinymce.activeEditor.targetElm).attr("data-uploadLink"),
//or use this if you want to override tinymce auto upload.
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
var uploadLink = $(tinymce.activeEditor.targetElm).attr("data-uploadLink");
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', uploadLink);
xhr.onload = function () {
var json;
if (xhr.status != 200) {
failure('HTTP Error: ' + xhr.status);
return;
}
json = JSON.parse(xhr.responseText);
if (!json || typeof json.location != 'string') {
failure(xhr.responseText);
return;
}
success(json.location);
};
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
xhr.send(formData);
}
});这里的重点是向你展示我如何从当前选择的tinymce实例中获得一个动态上传url到tinymce中。你上传的方式是你的选择,我希望你知道如何处理。但是另外,我提供了自动和自定义的例子。
https://stackoverflow.com/questions/13547122
复制相似问题