View previous topic :: View next topic |
Author |
Message |
webstar Smarty n00b
Joined: 02 Jun 2003 Posts: 2
|
|
Back to top |
|
xuguoxin Smarty n00b
Joined: 18 Apr 2003 Posts: 3
|
Posted: Fri Jun 06, 2003 10:02 am Post subject: Re: config datas from database |
|
|
webstar wrote: | in this thread (http://www.phpinsider.com/smarty-forum/viewtopic.php?t=13&highlight=config+data+database) I read it doesn't work until now.
I want to know if anyone have written a function which works like {config_load ....} but using a database?
Yesterday, I tried to do this. But unfortunately it didn't work. |
it is my problem |
|
Back to top |
|
[SuB] Smarty Rookie
Joined: 18 Jun 2003 Posts: 5
|
Posted: Wed Jun 18, 2003 9:26 am Post subject: |
|
|
Hi guys,
I just started using Smarty in one of our remotely hosted applications, and this feature is critical to me too.
I intend to put it into my extension class, so I will post the code here when I'm done... probably be in the next few days or so.
I will also submit it to the Smarty team and see if it helps them. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jun 18, 2003 7:46 pm Post subject: |
|
|
I once did something similar, but I write to mention that the developers are indeed working to try to get config_files to use resources. When it will happen, I don't know
Good luck. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jun 18, 2003 8:26 pm Post subject: |
|
|
It isn't in the core yet... that will probably be a little ways off yet. You can roll your own function, or extend the Config_File class to do what you need.
Monte |
|
Back to top |
|
[SuB] Smarty Rookie
Joined: 18 Jun 2003 Posts: 5
|
Posted: Tue Jul 08, 2003 6:41 am Post subject: |
|
|
Is it hard to implement? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Jul 08, 2003 7:40 am Post subject: |
|
|
Quote: | Is it hard to implement? |
If you mean to implement yourself, it is--straightforward. The main things you need to do are:
1) Create a new configuration class for your storage type. If your new class extends Config_File (current cvs) then you probably only need to override load_file() to deal with your specific storage type. Your class file should be stored in your Smarty dir and should be named using the same convention as used by Config_file.class.php.
2) set $smarty->config_class = 'your_class' when Smarty is instantiated (for example, in your custom Smarty class' constructor).
At this point, Smarty will now use your custom config class for config_load. If you want to enable multiple handling types (similar to resources, eg. 'db:default') then there is more work to do--more too than I list here. In this case, you will have to create a modified version of the default function plugin, function.config_load.php. Instead of using a resource naming scheme (which you can probably rig with some work) it is simpler to control the config class selection with a new custom parameter to config_load. There are certain issues to be considered (eg. managing instances of various config classes) which make this additional step less appealing.
Awhile ago I did a small experiment against 2.5.0 to support multiple types. I could probably find it if I looked around. It could be a starting point if you decided to support multiple types, but I would suggest trying the simpler approach. If you only intend to load configuration data from a single storage type, then steps 1 and 2 should be sufficient.
Good Luck! |
|
Back to top |
|
[SuB] Smarty Rookie
Joined: 18 Jun 2003 Posts: 5
|
Posted: Tue Jul 08, 2003 10:23 am Post subject: |
|
|
Seems simple enough... another testament to the good design of Smarty.
As a follow on, what's the reason it's not slated for short term inclusion into the core Smarty code? I presume cause you will want it to be a robust feature and not just a small add on? |
|
Back to top |
|
juchen Smarty n00b
Joined: 29 Aug 2003 Posts: 3
|
Posted: Thu Oct 30, 2003 3:15 am Post subject: |
|
|
This is a problem! |
|
Back to top |
|
|