问题
Im using CKeditor however i test it on a staging environment. Then i move it to production. The problem is when im linking i dont want to use mysite.com because then it will only work on staging or production but not on both. Instead i would like to use my basepath php variable which will auto determine to use mysite.com/ or staging.mysite.com
Is there any way to do this with the CKeditor URL link option. I have tried setting it to:
/myfolder/mypage.php
Using the other protocol, however it sets the URL as http///myfolder/mypage.php
Is this possible or is there an addon that can do this for me?
My config.js file as requested:
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
};
I did find out how to change the basepath for Ckeditor but this is just where ckeditor install path is, i need to set a different path which is just the basepath
Just to clarify as a picture speaks a thousand words and all:
Its this create a link option in the Ckeditor toolbar that allows you to create a URL link that i am referring to
回答1:
I know this isn't ideal as it's a hack, but you can go to ckeditor/plugins/link/dialogs/link.js
find this in the code:
label:i.protocol,"default":"http://",items:[["http://","http://"],["https://","https://"],["ftp://","ftp://"],["news://","news://"],[b.other,""]]
Then just add another option in the items
array like ["Base URL","/"]
.
I did find this solution that may also suit your needs: http://ckeditor.com/forums/CKEditor-3.x/internal-pages-dropdown-link-dialog
Hope that helps.
回答2:
Have a look at this page of the ckeditor documentation.
Here they say that you can set the basepath using this syntax:
<script>
var CKEDITOR_BASEPATH = '/ckeditor/';
</script>
<script src="all_my_scripts.js"></script>
I don't really understand what your issue really is. If you just set the basepath as a relative path like this you will never need to change it changing the environment. Just replicate the folder structure between development and production!
回答3:
Set the 'baseHref' of the ckeditor configuration to the current url of the environment you are currently on , 'http://staging.google.com' for instance . You can start using links relative to such path in your editor. If for instance you have url pointing to an image 'http://staging.google/images/example.jpg' you just insert '/images/example.jpg' in the editor and this should display the actual image. Hope this helps.
回答4:
I believe Mario Wakeel has the nearest answer so far (note that you need to be looking at baseHref and not basePath):
http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-baseHref
If you need to set this variable programmatically, I'm guessing you'd need to use some simple server-side code to check which domain the editor is being accessed from (before the config is loaded).
回答5:
If you take a look at the ckeditor.js you will see this line:
Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances.
So if you want to set the base path so that all upload file and link have the correct path, just prepend this line into ckeditor.js file
CKEDITOR_BASEPATH=your_relative_path
or you can set global variable like this
var CKEDITOR_BASEPATH = your_relative_path;
before you include ckeditor.js
来源:https://stackoverflow.com/questions/33318228/ckeditor-link-with-basepath