Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

FileUploadField for Images (ImageUploadField) SOLVED


Reply

8 Posts   1611 Views

Avatar
Cano

22 October 2010 at 4:18am (Last edited: 22 October 2010 7:17am), Community Member, 14 Posts

I can get uploadify to work perfectly in the back end, with files being added fine, but when I go to the front end, i get the following:

[User Error] Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'File'
GET /silverstripe/?isDev=1

Line 724 in C:\wamp\www\silverstripe\sapphire\core\Object.php
Source

715             
716             default :
717                throw new Exception (
718                   "Object->__call(): extra method $method is invalid on $this->class:" . var_export($config, true)
719                );
720          }
721       } else {
722          // Please do not change the exception code number below.
723          
724          throw new Exception("Object->__call(): the method '$method' does not exist on '$this->class'", 2175);
725       }
726    }
727    
728    // -----------------------------------------------------------------------------------------------------------------
729    
730    /**

Trace

* Object->__call(forTemplate,Array)
* File->forTemplate()
Line 447 of ViewableData.php
* ViewableData->XML_val(PagePhoto,,1)
Line 18 of .cacheC..wamp.www.silverstripe.themes.Vitruvian.templates.Layout.Page.ss
* include(C:\WINDOWS\Temp\silverstripe-cacheC--wamp-www-silverstripe\.cacheC..wamp.www.silverstripe.themes.Vitruvian.templates.Layout.Page.ss)
Line 420 of SSViewer.php
* SSViewer->process(Page_Controller,Zend_Cache_Frontend_Output)
Line 411 of SSViewer.php
* SSViewer->process(Page_Controller)
Line 202 of Controller.php
* Controller->handleAction(SS_HTTPRequest)
Line 137 of RequestHandler.php
* RequestHandler->handleRequest(SS_HTTPRequest)
Line 147 of Controller.php
* Controller->handleRequest(SS_HTTPRequest)
Line 199 of ContentController.php
* ContentController->handleRequest(SS_HTTPRequest)
Line 67 of ModelAsController.php
* ModelAsController->handleRequest(SS_HTTPRequest)
Line 111 of RootURLController.php
* RootURLController->handleRequest(SS_HTTPRequest)
Line 281 of Director.php
* Director::handleRequest(SS_HTTPRequest,Session)
Line 124 of Director.php
* Director::direct(/)
Line 127 of main.php

Any ideas?

Avatar
Cano

22 October 2010 at 4:41am Community Member, 14 Posts

FYI

page.php:

<?php
class Page extends SiteTree {
   
   public static $db = array(                  
      );

   public static $has_one = array(
                        
      'BannerImage' => 'File',
      'PagePhoto' => 'File',
   );
   
   function getCMSFields() {
      $fields = parent::getCMSFields();
         $fields->addFieldToTab('Root.Content.Main', new FileUploadField('BannerImage','Banner Image'), 'Content');
         $fields->addFieldToTab('Root.Content.Main', new FileUploadField('PagePhoto','Page Photo'), 'Content');
      return $fields;
   }

}
class Page_Controller extends ContentController {

   public static $allowed_actions = array (
   );
   
   public function init() {
      parent::init();

      Requirements::themedCSS('layout');
      Requirements::themedCSS('typography');
      Requirements::themedCSS('form');
      
   }
}

Avatar
UncleCheese

22 October 2010 at 5:14am 4085 Posts

If you look closely, that error isn't coming from Uploadify. It's coming from your template. Looks like you're trying to render a File object as output.

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
Cano

22 October 2010 at 5:26am Community Member, 14 Posts

Thanks for getting back to me, sorry Uncle Cheese, but im a bit of a Noob...

This makes sense as the file is uploaded and used as the header image in my page.ss template, is this not allowed? Is there a $BannerImage.SOMETHING that would render the file (image) out as an image?

Many (many) thanks for your help
+ thanks for your tutorials and video screencasts you provide for the community.

Avatar
UncleCheese

22 October 2010 at 5:29am 4085 Posts

Images have a forTemplate() method, but files don't. For File objects, you have to do something like:

<a href="$File.URL">Download ($File.Size) [$File.Extension]</a>

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
Cano

22 October 2010 at 5:41am Community Member, 14 Posts

So I shouldnt use uploadify to assign images to a variable? Apologies if this is obvious, i wanted to use uploadify as the UI is much cleaner for me/my client to use.

Avatar
UncleCheese

22 October 2010 at 6:07am 4085 Posts

Sure, of course you can. Just cast those relationships as 'Image' instead of file. And instead of "FileUploadField", use "ImageUploadField"

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
Cano

22 October 2010 at 7:15am Community Member, 14 Posts

That is disgustingly obvious not you say, thanks for getting me through!

Cheers,
Sam