Setting a variable in dashboard that is accessed from block and $pkg->saveConfig vs Config::save
Permalink 1 user found helpful
I made a paypal button block but would like to be able to set the paypal email address from the dashboard. The address could change but there is multiple areas its used. Going back and editing each block would be troublesome.
I need to make a dashboard page that stores the email address and then access it from either page controllers or blocks. I still don't know how to do this.
I've asked before about making dashboard pages and have checked out some peoples simple blocks that allow you to store some data via a dashboard page and pull it into a block, but I don't quite understand how its really working.
Can someone walk me through a basic example of this?
My first post on the matter a while back:
http://www.concrete5.org/community/forums/5-7-discussion/making-a-b...
Helpful links for others learning about single pages:
http://documentation.concrete5.org/developers/working-with-pages/si...
http://documentation.concrete5.org/api/class-Concrete.Core.Page.Sin...
I need to make a dashboard page that stores the email address and then access it from either page controllers or blocks. I still don't know how to do this.
I've asked before about making dashboard pages and have checked out some peoples simple blocks that allow you to store some data via a dashboard page and pull it into a block, but I don't quite understand how its really working.
Can someone walk me through a basic example of this?
My first post on the matter a while back:
http://www.concrete5.org/community/forums/5-7-discussion/making-a-b...
Helpful links for others learning about single pages:
http://documentation.concrete5.org/developers/working-with-pages/si...
http://documentation.concrete5.org/api/class-Concrete.Core.Page.Sin...
I think whats confused me about this all along is we don't have to declare a database schema. My mind is in building blocks mode. When we use Config, we can just give it data and it saves it somewhere??? Thanks for your example, it helped me finally figure this out.
Can you explain to me the different between using $pkg->getConfig()->save and doing Config::save ???
Is one method preferred over the other?
Can you explain to me the different between using $pkg->getConfig()->save and doing Config::save ???
Is one method preferred over the other?
I am not 100% sure about the difference but I believe they save the config in two different places. I'd have to poke around some to tell you for sure but I believe that's the case.
In addition, I think package configs get cleared when a package is uninstalled. Hence preferred for packages because it avoids clutter building up.
I don't know where package configs are saved, but I did some testing and it looks to me like the configuration actually persists. I have a checkbox that gets saved to the package config, whenever I uninstalled and reinstalled, the last settings of the checkbox persisted. I ended up presetting a value for the config variable on install to get around this.
As for using Config, I think it gets saved to application/config/generated_overrides, as for $pkg->getConfig, I do not know where that data is kept.
As for using Config, I think it gets saved to application/config/generated_overrides, as for $pkg->getConfig, I do not know where that data is kept.
Difference between $pkg->config and Config:: is:
$pkg->config saves the sql database, inside the table Config.
Config:: saves to a file in application/config/generated overrides..
$pkg->config saves the sql database, inside the table Config.
Config:: saves to a file in application/config/generated overrides..
Then in your view you would create an input field to let the user set this variable such as
Then you would have that input submit to your save function in the controller, in the save function you would need to write the value to the config like this
This will now be stored and you can access it from your block with the same code we had for the view function in the single page controller.
Make sure to change out the "your_package_handle", if you aren't putting this into a package you can refer to the post by @Korvin in this thread for the code to do it without, but the idea is the same -http://www.concrete5.org/community/forums/5-7-discussion/packagesav...