7919 Posts in 1358 Topics by 932 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Uploadify - multiple file upload
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 999 Views |
-
Uploadify - multiple file upload

8 September 2011 at 9:18pm
Hello,
this is primary a question for UncleCheese, but any1 who know the answer would be welcome to give it.
I have seen the code examples for DOM/Uploadify posted in this thread:
http://www.silverstripe.org/dataobjectmanager-module-forum/show/7009?start=0
and it works (I've tried it with a bit of different names for sth, but mainly the same thing). now I would like to be able to attach 2 files to same Dataobject. I've tried doing sth like:<?php
class Resource extends DataObject
{
static $db = array (
'Name' => 'Text',
'Description' => 'Text',
'Category' => "Enum('Industry, Finance, Education')"
);
static $has_one = array (
'Attachment' => 'File',
'MYFILE' => 'File,
'ResourcePage' => 'ResourcePage'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name'),
new TextareaField('Description'),
new DropdownField('Category','Category', singleton('Resource')->dbObject('Category')->enumValues()),
new FileIFrameField('Attachment'),
new FileIFrameField('MYFILE'),
);
}
}
?>and it doesn't work. I added sth like:
<?php
class ResourcePage extends Page
{
static $has_many = array (
'Resources' => 'Resource'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$manager = new FileDataObjectManager(
$this, // Controller
'Resources', // Source name
'Resource', // Source class
'Attachment', // File name on DataObject
'MYFILE', // Second file name on DataObject
array(
'Name' => 'Name',
'Description' => 'Description',
'Category' => 'Category'
), // Headings
.....
and it just gives out errors. Any ideas how to do this? I need 2 separate file uploaded in 2 different categorys in same Dataobject -
Re: Uploadify - multiple file upload

9 September 2011 at 7:12pm
Hey mate, I have tried that, didn't help much - for some reason just changing FileDataObjectManager to DataObjectManager doesn't do much help, if you had sth else in mind plz do tell.
Then I wanted to use the code you supplied on your website with frontend form for Jop aplication (kinda simmilar to what I want - it has a file and multifile upload thingie and it rly is all i need in the end.
The files can be found at this location:
http://www.leftandmain.com/silverstripe-tutorials/2010/08/30/using-uploadify-in-frontend-forms/Anyways, long story short, I have placed them in /ss/mycode and .../templates/layout folders as neaded, rebuilt a side (/dev/build) and I can go to admin interface and create a new JobAplicationPage, but then the following error pops up:
ERROR [Notice]: Undefined index: ManyS3File
IN POST /ss/admin/getitem?ID=430&ajax=1
Line 154 in /var/www/ss/sapphire/core/ClassInfo.phpSource
======
145: /**
146: * @todo Improve documentation
147: */
148: static function ancestry($class, $onlyWithTables = false) {
149: global $_ALL_CLASSES;
150:
151: if(is_object($class)) $class = $class->class;
152: else if(!is_string($class)) user_error("Bad class value " . var_export($class, true) . " passed to
ClassInfo::ancestry()", E_USER_WARNING);
153:
* 154: $items = $_ALL_CLASSES['parents'][$class];
155: $items[$class] = $class;
156: if($onlyWithTables) foreach($items as $item) {
157: if(!DataObject::has_own_table($item)) unset($items[$item]);
158: }
159: return $items;
160: }Trace
=====
<ul>ClassInfo::ancestry(ManyS3File)
line 426 of Object.phpObject::combined_static(ManyS3File,has_one,DataObject)
line 1334 of DataObject.phpDataObject->getRemoteJoinField(ManyS3Files,has_many)
line 1264 of DataObject.phpDataObject->getComponents(ManyS3Files)
call_user_func_array(Array,Array)
line 711 of Object.phpObject->__call(ManyS3Files,Array)
line 38 of MultipleFileUploadField.phpJobApplicationPage->ManyS3Files()
line 38 of MultipleFileUploadField.phpMultipleFileUploadField->setValue(,JobApplicationPage)
line 992 of Form.phpForm->loadDataFrom(JobApplicationPage)
line 490 of CMSMain.phpCMSMain->getEditForm(430)
line 1039 of LeftAndMain.phpLeftAndMain->EditForm()
line 389 of LeftAndMain.phpLeftAndMain->getitem(SS_HTTPRequest)
line 193 of Controller.phpController->handleAction(SS_HTTPRequest)
line 143 of RequestHandler.phpRequestHandler->handleRequest(SS_HTTPRequest)
line 147 of Controller.phpController->handleRequest(SS_HTTPRequest)
line 282 of Director.phpDirector::handleRequest(SS_HTTPRequest,Session)
line 125 of Director.phpDirector::direct(/admin/getitem)
line 127 of main.php</ul>
Plz help
-
Re: Uploadify - multiple file upload

10 September 2011 at 1:32am
Don't forget that DOM and FDOM have different constructors, so you'll need to remove one argument when going from FDOM to DOM.
--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com -
Re: Uploadify - multiple file upload

13 September 2011 at 12:21am
Mate I am probably boring my now, but I don't see the problem, can you fix this for me?
This is my actual code<?php
class Challenge extends DataObject{static $db=array(
'Naziv' => 'Text',
'Datum' => 'Date',
'Opis'=>'Text',
'Aktivan'=>'Boolean'
);
static $has_one=array(
'Izazov'=>'File',
'Razultati'=>'File',
'Izazovi' => 'Izazovi',
'IzazoviArhiva' => 'IzazoviArhiva'
);
public function getCMSFields_forPopup(){
return new FieldSet(
new TextField('Naziv','Naziv izazova'),
new DatePickerField('Datum'),
new TextField('Opis','Krataki opis'),
new FileIFrameField('Izazov'),
new FileIFrameField('Rezultati'),
new CheckboxField('Aktivan')
);
}
}
?><?php
/**
* Izazovi page type - sadrzi aktivne izazove
*/class Izazovi extends Page {
static $has_one = array(
'Photo' => 'Image'
);
static $allowed_children = array(
'IzazoviArhiva',
'Challenge'
);
static $has_many=array(
'Challenges'=>'Challenge'
);
static $db = array(
'Content' => 'Text'
);public function getCMSFields(){
$fields = parent::getCMSFields();
$manager = new DataObjectManager(
$this, // Controller
'Challenges', // Source name
'Challenge', // Source class
'Izazov', // File name on DataObject
'Rezultati', // File name on DataObject
array(
'Naziv' => 'Naziv',
'Datum' => 'Datum',
'Opis' => 'Opis',
'Aktivan'=> 'Aktivan'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
$fields->removeFieldFromTab('Root.Content.Main', 'Content');
$fields->addFieldToTab("Root.Content.Image", new ImageField('Photo','Slika'));
$fields->addFieldToTab('Root.Content.Main', new TextareaField('Content', 'Content', 20));
$fields->addFieldToTab("Root.Content.Izazovi",$manager);
return $fields;
}
}class Izazovi_Controller extends Page_Controller {
...and the error it gives me in /admin/ :
ERROR [Warning]: Invalid argument supplied for foreach()
IN POST /ss/admin/getitem?ID=19&ajax=1
Line 284 in /var/www/ss/dataobject_manager/code/DataObjectManager.phpSource
======
275: if(!$this->controller->ID && $this->isNested)
276: return $this->renderWith('DataObjectManager_holder');
277: return parent::FieldHolder();
278: }
279:
280:
281: public function Headings()
282: {
283: $headings = array();
* 284: foreach($this->fieldList as $fieldName => $fieldTitle) {
285: if(isset($_REQUEST['ctf'][$this->Name()]['sort_dir']))
286: $dir = $_REQUEST['ctf'][$this->Name()]['sort_dir'] == "ASC" ? "DESC" : "ASC";
287: else
288: $dir = "ASC";
289: $headings[] = new ArrayData(array(
290: "Name" => $fieldName,Trace
=====
<ul>DataObjectManager->Headings()
line 369 of ViewableData.phpViewableData->obj(Headings,,1)
line 245 of .cache.dataobject_manager.templates.DataObjectManager.ssinclude(/tmp/silverstripe-cache-var-www-ss/.cache.dataobject_manager.templates.DataObjectManager.ss)
line 420 of SSViewer.phpSSViewer->process(DataObjectManager)
line 342 of ViewableData.phpViewableData->renderWith(DataObjectManager)
line 275 of ComplexTableField.phpComplexTableField->FieldHolder()
line 277 of DataObjectManager.phpDataObjectManager->FieldHolder()
line 369 of ViewableData.phpViewableData->obj(FieldHolder,,,1)
line 446 of ViewableData.phpViewableData->XML_val(FieldHolder,,1)
line 73 of .cache.sapphire.templates.TabSetFieldHolder.ssinclude(/tmp/silverstripe-cache-var-www-ss/.cache.sapphire.templates.TabSetFieldHolder.ss)
line 420 of SSViewer.phpSSViewer->process(TabSet)
line 342 of ViewableData.phpViewableData->renderWith(TabSetFieldHolder)
line 80 of TabSet.phpTabSet->FieldHolder()
line 369 of ViewableData.phpViewableData->obj(FieldHolder,,,1)
line 446 of ViewableData.phpViewableData->XML_val(FieldHolder,,1)
line 58 of .cache.sapphire.templates.TabSetFieldHolder.ssinclude(/tmp/silverstripe-cache-var-www-ss/.cache.sapphire.templates.TabSetFieldHolder.ss)
line 420 of SSViewer.phpSSViewer->process(TabSet)
line 342 of ViewableData.phpViewableData->renderWith(TabSetFieldHolder)
line 80 of TabSet.phpTabSet->FieldHolder()
line 369 of ViewableData.phpViewableData->obj(FieldHolder,,,1)
line 446 of ViewableData.phpViewableData->XML_val(FieldHolder,,1)
line 77 of .cache.sapphire.templates.Includes.Form.ssinclude(/tmp/silverstripe-cache-var-www-ss/.cache.sapphire.templates.Includes.Form.ss)
line 420 of SSViewer.phpSSViewer->process(Form)
line 342 of ViewableData.phpViewableData->renderWith(Array)
line 1108 of Form.phpForm->forTemplate()
line 1135 of Form.phpForm->formHtmlContent()
line 391 of LeftAndMain.phpLeftAndMain->getitem(SS_HTTPRequest)
line 193 of Controller.phpController->handleAction(SS_HTTPRequest)
line 143 of RequestHandler.phpRequestHandler->handleRequest(SS_HTTPRequest)
line 147 of Controller.phpController->handleRequest(SS_HTTPRequest)
line 282 of Director.phpDirector::handleRequest(SS_HTTPRequest,Session)
line 125 of Director.phpDirector::direct(/admin/getitem)
line 127 of main.php</ul>
-
Re: Uploadify - multiple file upload

13 September 2011 at 1:48am
Look at the API for FDOM versus DOM. This argument does not exist in DOM:
'Izazov', // File name on DataObject
-
Re: Uploadify - multiple file upload

13 September 2011 at 10:13pm Last edited: 14 September 2011 1:47am
Hey mate, thank you, i figured it out, you helped a lot.
Btw, how to formulate a <% if $Rezultati %> in .ss file so that if there is a filed uploaded it would show it, if not then nothing?I have tried this:
<% control getChallenges(2) %>
<h3>$Naziv</h3>
<p class="document_text"><b>Datum:</b> $Datum</p>
<p class="document_text"><b>Kratki opis:</b> $Opis</p>
<p> <a href="$Izazov.URL">Preuzmi izazov</a></p>
<% if $Rezultati %>
<p>Rezultati izazova:</p>
<p> <a href="$Razultati.URL">Rezultati</a></p>
<% end_if %>
</br>
<% end_control %>but it doesn't work... I need $Rezultati file to only be shown once it is uploaded, since the Iizazov file is some kind of a challenge, and once the certain amount of time has passes we will announce the ppl who managed to finish it and show resaults in $Rezultati (pdf file) so once that is uploaded for that particular challenge it is supposed to be shown.
EDIT:
Been trying with return file_exists($this->Rezultati); in some function but it doesn't work also, always returns bool(false) so I rly don't know how to check if there is a file uploaded or not.
EDIT2:
works, had a typo in filename
-
Re: Uploadify - multiple file upload

14 September 2011 at 5:13am
Also you don't want the $ in the if statement. Prepending a $ before the variable name will render its output to the template, and that's not what you want.
<% if MyFile %> not <% if $MyFile %>
--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com
| 999 Views | ||
|
Page:
1
|
Go to Top |

