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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

A few questions to improve usability


Go to End


6 Posts   826 Views

Avatar
Schippie

Community Member, 38 Posts

16 June 2014 at 10:32pm

Edited: 17/06/2014 1:12am

Hello, i have been having a few questions related to Silverstripe for a while and was looking for an answer to them so here goes.

  • - What is the best way to change the image file name upon uploading? This has to be specific to only that one uploader (applies to frontend and backend).
  • - What is the best way to extend the Image class adding a couple of fields to the file (in a separate table ). And selecting this class on the uploadfield. The problem right now is their is a getter located: http://api.silverstripe.org/3.1/source-class-File.html#_get_class_for_file_extension in the File DataObject class. Though this one only looks for extensions and the one in http://api.silverstripe.org/3.1/source-class-FileField.html#_saveInto only looks for has_one relations but not for has_many relations. So its impossible to extend an Image -> upload and image and have it save them with a has_many relation to the other DataObject.
  • - Like i posted in the template forums: http://www.silverstripe.org/template-questions/show/58111 I am still looking for a way to restructure the template folder to have it more based on the url path so: http://website.com/team/backend/wedstrijd should correspond to folder: <mysite>/templates/team/backend/wedstrijd/
  • - I have been having some trouble with the routing from time to time, eventually i always fix it but it has been bothering me quite a bit. Having to create multiple:

    ---
    Name: myroutes
    After: framework/routes#coreroutes
    ---
    Director:
      rules:

    Blocks in a specific order to get a path to work for example, i want the following rules to go to the correct controller:

    • 1: 'team': 'TeamController'
    • 2: 'team/$teamID': 'TeamSingleController'
    • 3: 'team/$teamID/wedstrijd': 'TeamWedstrijdController'

    The problem is team will go to the TeamSingleController or TeamWedstrijdController instead of the TeamController.
    Changing the order also never really seems to have an effect but creating multiple routes configs with different names generally works.

Avatar
camfindlay

Forum Moderator, 267 Posts

17 June 2014 at 10:30am

Hey Schippie,

You might be best to split your questions out into separate topic focused threads with a good descriptive title. You might be more likely to get a response. Asking all these questions in one block might be a bit daunting for someone to tackle and try give you an answer.

Avatar
Willr

Forum Moderator, 5523 Posts

28 June 2014 at 8:04pm

2) Use a DataExtension on the image class alongside an updateCMSFields.

4) Make sure your routes are from most specific to least specific as the first route that matches, will get used.

Avatar
Schippie

Community Member, 38 Posts

29 June 2014 at 1:04am

Will try and see if 4 sorts it self out by doing it from one correctly. For point 2 this is not really a solution in my opinion. While yes i could extend it and add data that way this still gives me no option if i want to completely change the way the image class works in key area's the fact the code has no option on the uploadfield to specify the dataObject you wish to use for processing strikes me as odd. And that's a feature i would really like to see improved.

That just leaves question 1 and 3 to be answered.

Avatar
Willr

Forum Moderator, 5523 Posts

29 June 2014 at 10:38am

2) To expand on that If you really did want to dramatically replace the class then you would use the Injector system (http://doc.silverstripe.org/framework/en/reference/injector). This is however new, and a few parts of the core are not quite updated so you will likely run into issues in the short term but more places are being updated as time allows.

Sorry I haven't got a nice answer for 1, I know you'd need to customize UploadField but at the moment, only way to rename would be in the assets section. If the name is programatic then you could rename the file onBeforeWrite() of the Image object.

For 3 again, I don't think I have a nice answer. AFAIK nested folders in templates (even for categorising template types) is not supported but it did change in 3.0. In theory it should be supported or a pretty simple task in core as there already exists a manifest of templates which could include directories (much like the classmanifest). Would need a few tests and documentation but defiantly a doable enhancement to core if someone wanted to tackle it (or fund development).

Avatar
Schippie

Community Member, 38 Posts

29 June 2014 at 9:44pm

2) To expand on that If you really did want to dramatically replace the class then you would use the Injector system (http://doc.silverstripe.org/framework/en/reference/injector). This is however new, and a few parts of the core are not quite updated so you will likely run into issues in the short term but more places are being updated as time allows.

Oh that could be a nice solution in the future. Having read quickly over it i am left with the question how in this way i would go about overriding a single method of a class.
Though i could with injectors override the http://api.silverstripe.org/3.1/source-class-File.html#$class_for_file_extension to point to my own array. Even though that would mean it applied to all the file dataObjects.

Sorry I haven't got a nice answer for 1, I know you'd need to customize UploadField but at the moment, only way to rename would be in the assets section. If the name is programatic then you could rename the file onBeforeWrite() of the Image object.

I guess i could use http://api.silverstripe.org/3.1/source-class-Object.html#_useCustomClass to rewrite the UploadField class and maybe the File class to allow the setting of a custom dataObject upon the creation of the uploadField. By passing another argument to the constructor.

For 3 again, I don't think I have a nice answer. AFAIK nested folders in templates (even for categorising template types) is not supported but it did change in 3.0. In theory it should be supported or a pretty simple task in core as there already exists a manifest of templates which could include directories (much like the classmanifest). Would need a few tests and documentation but defiantly a doable enhancement to core if someone wanted to tackle it (or fund development).

Really hope to see this improved, even though that would probably take a while. Would like to see a system in place that would allow me more flexibility. Like for example:

- Each template needs a unique name.
- The structure of the folders within the template directory is fully changeable.
- The renderWith function allows you to more precisely specify what you want to render with what for example:

$this->renderWith(array(
   "view" => "template name",
   "layout" => "template name",
   "content" => "template name"
));

This would also be more clear then the current way were the layout template is specified first followed by the view(page) template. And could allow you to have multiple templates be auto rendered without having to specify custom functions for it on the controller (or page controller) like for example different sidebar(s). Configured like this:

$this->renderWith(array(
   "view" => "template name",
   "layout" => "template name",
   "sidebarA" => "sidebar A template name",
   "sidebarB" => "sidebar B template name"
));