How to specify image folder path for each user when use TinyMce ImageManager with Symfony
First, in sfWidgetFormTextareaTinyMce class we set:
protected function configure($options = array(), $attributes = array())
{
......
$this->addOption('imagemanager_rootpath', 'mydir');
......
}
public function render($name, $value = null, $attributes = array(), $errors = array())
{
$textarea = sfWidgetFormTextarea::render($name, $value, $attributes, $errors);
$js = sprintf(<<<EOF
<script type="text/javascript">
tinyMCE.init({
mode: "exact",
elements : '%1\$s',
imagemanager_rootpath: '{0}/%2\$s',
.....
}
Second, i set a 'imagemanager_rootpath' value in action, to throw the value to form:
public function executeCreate(sfWebRequest $request)
{
...
$this->form = new TextForm(null, array('imagemanager_rootpath' => $user_id));
...
}
Last, in the TextForm class, we configure the path:
public function configure()
{
....
$path = $this->options['imagemanager_rootpath'];
$user_dir = $_SERVER['DOCUMENT_ROOT'].'/uploads/submission/text/'.$path;
if (!is_dir($user_dir)) mkdir($user_dir, 0777);
$this->widgetSchema['content'] = new sfWidgetFormTextareaTinyMCE(array('width' => 480, 'height' => 250, 'imagemanager_rootpath' => $path));
....
}
more detail: http://www.tinymce.com/wiki.php/MCImageManager:rootpath

浙公网安备 33010602011771号