Question

I need to set the path and root path for the image manager based on various scenarios.

Same user may use the image manager to upload images from different pages. I want to send a parameter from the client side to indicated the scenario. For example, if the user is using the editor in home page, send home; similarly, if using in contact us page send contact. All I can do is set the root path on client side during init. For example, imagemanager_rootpath: "test". But my path is computed on server side based on the parameter I send. Is there any way to do this.

Was it helpful?

Solution

From what I understand of your issue, you have two options:

1: Generate the Javascript from a template on the server (Say using Smarty or equivalent) and insert the correct root path into the TinyMCE init code.

So, in straight PHP, you might end up with something like this:

<?php
$root_path = get_root_path();
?>

// Other javascript goes here

tinymceInstance = tinyMce.init({
    //parameters
    imagemanager_rootpath: "<?php echo $root_path ?>"
});

2: Generate a Javascript parameter file that contains all the parameters you want the Javascript to have, then use this when initialising the tinyMCE instance.

Parameter file:

<?php
echo "window.serverParameters = ".json_encode(array("imageRoot" => get_root_path()));
?>

HTML:

<html>
    <head>
        <script src="serverParameters.php" type="text/javascript" />
    </head>
</html>

Javascript:

tinymceInstance = tinyMce.init({
    //parameters
    imagemanager_rootpath: window.serverParameters.imageRoot
});

Hope that helps!

OTHER TIPS

At the moment, I could not find a better way to do this. I ended up creating a helper method that takes in a parameter indicating a resource type and determines the root path and sets the Session["imagemanager.filesystem.rootpath"] = "someRootPath". In the controller that returns a view with the editor, I call this helper method. There are few disadvantages to this. One is that the helper method is called upfront regardless of you using the image manager. My initial approach was to set the path once the image manager was clicked. So, do not call the helper method if the editors in the view do not use image manager. The second disadvantage to this is that if you have multiple editors on the same view but they need to upload to different locations; this is not possible. All the editors use the same root path set in the session. Again, the better approach would be to send a value from each editor to the server and set the root path. One way to use multiple locations is to get all the location and set them in the init() of the tinyMce editor using magemanager_rootpath: "someRootPath". One advantage to this, however, is that, if your view uses multiple editors and they all use the same location within that view, the helper method is called only once instead of multiple times with the original approach. So, I'm marking Skurrier's answer as correct but leave comments if you find a better approach.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top