Description
This script is meant to store and retrieve variables in a central place. The values can be stored in three ways.
- Temp: Variables are accessible withing one script execution (like normal variables).
- Session: Variables that are accessible from all the pages for one user (saved in session).
- Application: Variables are accesible for all users from all pages (saved in file).
This way you have all your variables in one place and have a central place the get and set your different type of variables.
Freatures
- Set and retrieve variables with the same method.
- Static methods so easy to use
- Binding variables in the registry to keep a reference
- Set and get to/from sessions/file/variables with the same method
- Auto serializing of arrays and objects before saved to file
How to use
The class is very easy to use because it uses static methods and uses the singleton pattern so there’s always only one instance from the class.
For example we want to save the username in a session so it’s accessible from every page in your website.
Registry::Set("username", "Sitebase", Registry::VAR_SESSION);
If I now want to access the username of the current user. You do this:
echo Registry::Get("username");
A second example is setting a variable that is accessible on every page and for every visitor on the website. The variables are stored in a ini file (in upcoming release it will also be possible to save to database). First we need to add a driver for the Ini file to the registry. This you do once in your index.php file.
$Driver = new Registry_Drivers_Ini(); $Driver->SetFile("data.ini"); Registry::SetDriver($Driver);
To save a variable to the ini file you do this:
Registry::Set("localhost", "host", Registry::VAR_APPLICATION);
If I now want to access the the host variable you do this:
echo Registry::Get("host");
If you use an array or object as variable then these will automaticly be serialized before saving to the ini file. This way you can save whatever type of variable you want in the ini file.
[eltd_button size=”huge-full-width” type=”outline” text=”Download & Demo Links” custom_class=”#” icon_pack=”font_awesome” fa_icon=”” link=”” target=”_blank” color=”” hover_color=”” background_color=”” hover_background_color=”” border_color=”” hover_border_color=”” font_size=”” font_weight=”” margin=””]
Demo = Registry Class
[eltd_button size=”huge” type=”” text=”Full Live Demo” custom_class=”” icon_pack=”font_awesome” fa_icon=”fa-laptop” link=”https://codecanyon.net/item/registry-class/72561″ target=”_blank” color=”” hover_color=”” background_color=”” hover_background_color=”” border_color=”” hover_border_color=”” font_size=”” font_weight=”” margin=””]
Kindly Note: We update new contents like WordPress Themes, Plugins, PHP Scripts everyday. But remember that you should never use this items in a commercial website. All the contents posted here for development & testing purpose only. We’re not responsible for any damage, use at your own RISK! We highly recommend to buy Registry Class from the The Developer ( Sitebase ) website. Thank you.
Download = Registry Class-[Updated].zip