Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » FileUploadField for Images (ImageUploadField) SOLVED

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1580 Views
  • Cano
    Avatar
    Community Member
    14 Posts

    FileUploadField for Images (ImageUploadField) SOLVED Link to this post

    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?

  • Cano
    Avatar
    Community Member
    14 Posts

    Re: FileUploadField for Images (ImageUploadField) SOLVED Link to this post

    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');
          
       }
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: FileUploadField for Images (ImageUploadField) SOLVED Link to this post

    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

  • Cano
    Avatar
    Community Member
    14 Posts

    Re: FileUploadField for Images (ImageUploadField) SOLVED Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: FileUploadField for Images (ImageUploadField) SOLVED Link to this post

    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

  • Cano
    Avatar
    Community Member
    14 Posts

    Re: FileUploadField for Images (ImageUploadField) SOLVED Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: FileUploadField for Images (ImageUploadField) SOLVED Link to this post

    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

  • Cano
    Avatar
    Community Member
    14 Posts

    Re: FileUploadField for Images (ImageUploadField) SOLVED Link to this post

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

    Cheers,
    Sam

    1580 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.