首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Codeigniter: TinyMCE镜像管理器动态镜像路径

Codeigniter: TinyMCE镜像管理器动态镜像路径
EN

Stack Overflow用户
提问于 2012-11-25 08:27:33
回答 2查看 3.1K关注 0票数 5

我已经在我的codeigniter版本中安装了TinyMCE,并且还包含了镜像管理器。

在镜像管理器插件(保存在public/assets文件夹中)中有一个php配置文件,它定义了镜像和文件路径常量。

代码语言:javascript
复制
define('DIR_IMAGES', 'images/path/here'); etc

我的问题是,我需要的路径是动态的,取决于数据库中的一些数据,例如template_name,但我不知道如何在配置文件中包含正确的文件,以便我可以查看动态信息。

因此,如果用户保存了template_name,那么我需要的路径是

代码语言:javascript
复制
define('DIR_IMAGES', $template_name.'images/path/here');

我还在core/MY_Controller.php中的一个常量中定义了template_name,因此如果我可以访问该变量,这将比查询数据库更容易,但这两种方法都可以工作。

有人能帮我一下吗,非常感谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-13 10:40:30

我只定制了tinymce镜像,但没有使用TinyMCE镜像管理器。

但我使用下面的链接中的教程。

How-to implement a custom file browser

代码语言:javascript
复制
<!-- 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>
票数 2
EN

Stack Overflow用户

发布于 2018-06-02 13:41:35

将"data-“属性添加到tinymce元素,并从那里回显您想要的url。然后在tinymce activeEditor中,访问该数据属性值。

Textarea

代码语言:javascript
复制
<textarea name="description" class="tinymceDescription" data-uploadLink="<?php echo DIR_IMAGES; ?>" ></textarea>

TinyMce

代码语言:javascript
复制
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中。你上传的方式是你的选择,我希望你知道如何处理。但是另外,我提供了自动和自定义的例子。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13547122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档