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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

HasManyFileManager: New CMS module/extension. Testers/review needed


Go to End


62 Posts   109893 Views

Avatar
vstrazz

Community Member, 63 Posts

11 October 2008 at 6:12am

First off, Banal thank you. This is a great addition to silverstripe. Thank you for your hard work.

I installed this mod on a development site, and it worked fine. I went to install this on a live production site soon after and encountered some errors.

I think I have narrowed down the errors to having something to do with the ecommerce module. The development site I initially installed this on did not have ecommerce but once I put ecommerce on there, I received the same errors that I received on the other site.

this is the debug output.

FATAL ERROR: DATABASE ERROR: Couldn't run query: SELECT `File`.ID, `File`.ClassName, `File`.Created, `File`.LastEdited, `File`.Name, `File`.Title, `File`.Content, `File`.ParentID, `File`.Filename, if(`File`.ClassName,`File`.ClassName,'File') AS RecordClassName, `File`.PopupWidth, `File`.PopupHeight, `File`.Embed, `File`.LimitDimensions FROM `File` LEFT JOIN `Product_Image` ON `Product_Image`.ID = `File`.ID WHERE (File.SiteTreeID = 8) AND (File.Grouping = 'MyImages') ORDER BY Grouping, Sort | Column 'Grouping' in order clause is ambiguous
At line 431 in /var/www/vhosts/mysite.com/subdomains/dev/httpdocs/sapphire/core/model/Database.php

any ideas?

Avatar
bummzack

Community Member, 904 Posts

11 October 2008 at 6:41am

@vstrazz
There seems to be a conflict between the File Table and the Product_Image Table. Both seem to have a Grouping field.
I changed my code, so that it's no longer ambiguous.

You can get the updated code from SVN or just replace Line 15 of filemanager/code/SiteTreeFileHandler.php with the following line:

public function AttachedFiles($group = '', $sort = 'File.Grouping, File.Sort'){

Hope that helps!

Avatar
vstrazz

Community Member, 63 Posts

11 October 2008 at 6:58am

Thanks Banal, my apologies if this was discussed earlier in the thread and I missed it. I am extending this module to be able to show random uploaded images and link each image to the sponsor page. This made it tons easier.

Avatar
bummzack

Community Member, 904 Posts

11 October 2008 at 7:19am

Don't apologize. This was an issue i wasn't aware of and i fixed it right now, after you posted the problem.
I hope you post a link to the site, once it's done so we can all enjoy :)

Avatar
vstrazz

Community Member, 63 Posts

11 October 2008 at 8:11am

Don't apologize. This was an issue i wasn't aware of and i fixed it right now, after you posted the problem.
I hope you post a link to the site, once it's done so we can all enjoy :)

Cool, I helped out! :-D

Will do. I got the random image working with your module, and it handles the link to image relationship as well. pretty easy. If anyone would like to see the code just let me know.

Thanks again Banal

Avatar
Tyndie

Community Member, 9 Posts

13 October 2008 at 8:47am

Hi,

I would like to be able to attach pdf's to a type 'page' which will have an article, but have the pdf's upload to a certain folder which has already been created.

Is this possible?

Avatar
bummzack

Community Member, 904 Posts

13 October 2008 at 10:30am

@Tyndie

If you want to upload just one pdf per page, you don't really need the HasManyFileManager and you could simply use the FileField (or FileIFrameField) Class. By setting the last parameter of the constructor, you can change the upload folder for the file.

If you need multiple files per page, you can use the HasManyFileManager, but you have to change some things in order to get your files created in the desired folder.
You can change the base folder in the file AttachedFile.php on line 76

static $baseFolder = 'Uploads/AttachedFiles';

Whenever you create a HasManyFileManager you also specify a name, that is used for file grouping. This also creates a subfolder where files belonging to that group are being stored. You should consider this behavior too!

Example: If you need your files to be in Uploads/PDF, you should set the $baseFolder to 'Uploads' and the group name of the HasManyFileManager to 'PDF'.

Hope that helps.

Avatar
Tyndie

Community Member, 9 Posts

13 October 2008 at 9:16pm

Is there anyway of overriding the upload folder in the pagetype:

For example this is my page type:

<?php

class Screening extends Page {
	static $db = array(
	);
	
	static $has_many = array(
	'Files' => 'File',
	);
	
	function getCMSFields() {
	$fields = parent::getCMSFields();
 	static $baseFolder = 'Uploads/Programme-Notes/Season-2008-2009'; 
    $manager = new HasManyFileManager(
        $this,
        'PDF', // name -> will be used for file grouping
        'Files' // relation name defined in $has_many
    );
    // creating tab for the "Files" Manager
    $fields->addFieldToTab('Root.Content.Files', $manager, $baseFolder);

			
	   return $fields;
	}
	//static $icon = "tutorial/images/treeicons/news";
	public function onBeforeDelete(){
    parent::onBeforeDelete();
    $this->deleteAttachedFiles();
}

}
 
class Screening_Controller extends Page_Controller {
 
}
 
?>

I also have a gallery page for all programme notes by season, which is why I would like to specify where the files will go. Sometimes there will be more than one file, maybe images too.