7912 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » FileUploadField for Images (ImageUploadField) SOLVED
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: | 1306 Views |
-
FileUploadField for Images (ImageUploadField) SOLVED

22 October 2010 at 4:18am Last edited: 22 October 2010 7:17am
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=1Line 724 in C:\wamp\www\silverstripe\sapphire\core\Object.php
Source715
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.phpAny ideas?
-
Re: FileUploadField for Images (ImageUploadField) SOLVED

22 October 2010 at 4:41am
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');
}
} -
Re: FileUploadField for Images (ImageUploadField) SOLVED

22 October 2010 at 5:14am
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 -
Re: FileUploadField for Images (ImageUploadField) SOLVED

22 October 2010 at 5:26am
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. -
Re: FileUploadField for Images (ImageUploadField) SOLVED

22 October 2010 at 5:29am
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 -
Re: FileUploadField for Images (ImageUploadField) SOLVED

22 October 2010 at 5:41am
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.
-
Re: FileUploadField for Images (ImageUploadField) SOLVED

22 October 2010 at 6:07am
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 -
Re: FileUploadField for Images (ImageUploadField) SOLVED

22 October 2010 at 7:15am
That is disgustingly obvious not you say, thanks for getting me through!
Cheers,
Sam
| 1306 Views | ||
|
Page:
1
|
Go to Top |

