Wednesday, April 16, 2008

how to user symfony sfAjaxUploaderPlugin

This is from symfony forum

http://www.symfony-project.org/forum/index.php/mv/msg/9279/0/40/

for more information, please check the post.




It looks to me like many people having problems using this plugin, and for good reasons. It is not the best plugin around and it was built very quickly, but it can be used.

To help you all I have made a small demo project which I friezed and attached.

The project was build by init a new project, then init an application called "test" and then init module called "test".


The index template contains the form with a file input field to be uploaded.



Theses are the changes done to various files:

filters.yml:


rendering: ~
web_debug: ~
security: ~

# generally, you will want to insert your own filters here
ajaxUploader:
class: AjaxUploaderFilter

cache: ~
common: ~
flash: ~
execution: ~




settings.yml:


prod:
.settings:
no_script_name: on

dev:
.settings:
error_reporting:

web_debug: on
cache: off
no_script_name: off
etag: off

test:
.settings:
error_reporting:
cache: off
web_debug: off
no_script_name: off
etag: off

all:
.settings:
enabled_modules: [default, ajaxUploader]




view.yml


default:
http_metas:
content-type: text/html

metas:
title: symfony project
robots: index, follow
description: symfony project
keywords: symfony, project
language: en

stylesheets: [main]

javascripts: [%SF_PROTOTYPE_WEB_DIR%/js/prototype, /sfAjaxUploaderPlugin/js/ajaxUploader]

has_layout: on
layout: layout





There is no code in the actions, only some templates.

The index template is a form with file field:




'myAjaxUploader()',
'update' => 'target_div',
'url' => 'test/upload',
)); ?>









and the response template just echos some info:


getParameter('name'))) {
echo "file " . $sf_request->getParameter('name') . " was uploaded";
} else {
echo "no file was uploaded";
}
?>





The AjaxUploaderHelper.php was buggy (as few of you have noticed). It should be:

url_for("ajaxUploader/uploader") . "?name=$name", "name"=>"ajaxUploader", "frameborder"=>0, "width"=>320, "height"=>25), true)
. tag("/iframe") . input_hidden_tag($name);
}

?>





And thats it, AJAX uploads!

No comments: