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

Is it possible to generate page type properties in a function?


Go to End


6 Posts   1324 Views

Avatar
mattupstate

Community Member, 12 Posts

3 August 2011 at 2:04am

I have a page type that, at times, my client has wanted me to update the amount of rows and columns that are available to add content into. Rather than having to manually add more page properties I want to run a function that takes a row and column amount to append the static $db variable. Is there a scope in which I can run this function so that the reflection on the $db variable can still take place?

Avatar
swaiba

Forum Moderator, 1899 Posts

3 August 2011 at 2:52am

Hi Matt,

It is possible to read the php file, modify it, write it back to disk and then trigger a dev/build -sure.

"self-modifying" code is seen as a bad practice - I'd say it was because the code could wipe itself out and damage the system. This is because code can have mistakes, when it modifies itself with a mistake it would be magnified. "automatic programming" on the other hand (using software to create software) would be much better... I'm looking forward to SilverSmith by UncleCheese (http://www.leftandmain.com/silverstripe-screencasts/2011/04/11/the-silversmith-framework-code-right-type-less-build-fast/)- shouldn't be long now...

Barry

Avatar
Willr

Forum Moderator, 5523 Posts

3 August 2011 at 7:14pm

Yeah editing the code = bad idea. You should take a look at your data model, if you need to create multiple instances of the same thing then you should be looking to create a has_many relationship or splitting out those fields to another object that you can repeat.

Avatar
mattupstate

Community Member, 12 Posts

5 August 2011 at 3:55am

has_many generally relies on popup editors, does it not?

Avatar
swaiba

Forum Moderator, 1899 Posts

5 August 2011 at 4:10am

yes

Avatar
Willr

Forum Moderator, 5523 Posts

5 August 2011 at 9:07am

TableListFields (like the one in 'Security') can also do simple fields inline in the table which works well if you have title -> link type data.