Re: [SMARTY] defining arrays in config files
| From: | Tarik ANSARI | Date: | Mon, 23 Feb 2004 21:04:21 +0000 |
| Subject: | Re: [SMARTY] defining arrays in config files | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11010@lists.php.net to get a copy of this message | ||
We agree that config files should only contain static var. And the key value
of arrays vars should be importable from php because you want to link your
error codes in php to your config file errors messages (or anything else
than errors, that's a sample). And the fastest method and that save the most
memory when the script execute is to use constant in array key definition
because at compilation they are replace by their numerical value. We can
define those constant's numerical value in php automaticaly by an enum for
example :
function enum()
{
$ArgC = func_num_args();
$ArgV = func_get_args();
for($Int = 0; $Int < $ArgC; $Int++) define($ArgV[$Int], $Int);
}
enum("Const1", "Const2");
and then we get thoses constant in smarty config files for arrays's key
values, with $smarty.const.Const1, that is the smartest and the more
powerfull way I think...
That common way to work in C thanks to the performance of the method, and
for Smarty all the config var stay constants.
I agree that the example :
bar.$key_string1 = blabla
is unusefull, because if we works with strings to link messages, then we
link with string :
config file:
[section]
msg.AuthSuccessful = "Login Ok, welcome"
php:
$errno = "AuthSuccessful";
$smarty->assign("errno", $errno):
tpl:
{#msg.$errno#}
and with constant we have :
config file:
[section]
msg[$smarty.const.AuthSuccessful] = "Login Ok, welcome"
php:
// at the top of script
enum("AuthSuccessful", other errno...)
$errno = AuthSuccessful;
$smarty->assign("errno", $errno):
tpl:
{#msg[$errno]#}
Then it's evident that the most needed php imported var for config file are
constants, and we could even define the syntax to be $Const1 to directly
access a constant instead of $smarty.const.Const1 for inside config files.
But I won't say anything on that because I think keeping tpl inside syntax
is a good thing, then that's not necessary.
Tarik
"Monte Ohrt" <monte@ispi.net> a écrit dans le message de
news:1077568211.8380.87.camel@cyrus.ispi.prv...
> On Mon, 2004-02-23 at 13:55, Tarik ANSARI wrote:
> > I think that it's exactly what we gonna do. This syntax highlighted as
well
> > to me to be used in config files following the logic of the template
syntax
> > as described in the doc.
> > Moreover, we need to support key assignation :
> >
> > [section]
> > foo.bar[0] = testme
> > foo.bar[1] = testme2
> > bar[0].foo = blabla
>
> numerical indexes are probably ok, they are valid smarty syntax.
>
> >
> > as well as key names coming from php constants or assigned php variables
:
> >
> > [section]
> > foo.bar[$ERRNO1] = testme
> > foo.bar[$smarty.const.ERRNO2] = testme2
> > bar.$key_string1 = blabla
> > bar.$ERRNO3
>
> This I'm skeptical about. IMHO config files should contain static
> name=value pairs, nothing more. Anything beyond that should be handled
> outside of the config file. Maybe your particular problem should be
> understood better (by us) before we go diving in and complicating config
> file logic.
>
> Another alternative is to use a custom config file resource, I believe
> messju added that support recently.
>
> Monte