using config variables in language files |
[eluser]jbowman[/eluser]
I have a working solution for this, but something tells me it's not the best solution and I'm creating too much overhead. So I thought I'd throw it out there and see if anyone else has a better solution. Here's the situation. I'm creating my own user auth system. Yea I know there's plenty out there, none quite fit what I wanted, and I needed something that was adaptable for several sites I want to build. One thing I am doing is age verification on registration. However, some of the sites have different requirements. So.. I create a new config file site_config.php and have it autoloaded. It includes Code: $config['min_age'] = 14; I use formdate, and some playing with post variables afterwards to get a date string that I pass to my validation library (MY_validation.php, extending the CI one) through this function Code: /** Now if that returns false, it goes to my language file (which I'm going to be following this post up with another one to ask a question about that :) ) where I have Code: $lang['validate_age'] = 'You must be ' . get_instance()->config->item('min_age') . ' or older to complete this request.'; That get_instance is creating a whole new block of memory instead of referencing the existing one, isn't it? Is there a better way to handle this?
[eluser]maffo[/eluser]
Did you ever find a solution for this? Might save me some time if it has been done before as I need exactly the same functionality.
[eluser]maffo[/eluser]
If only it were that easy my friend, you cant use config or session data within the language files.
[eluser]Armchair Samurai[/eluser]
Considering the original poster posted this about three months ago, I'm assuming they've found a solution to this problem. But since the thread was pulled from its grave like a member of the undead, this works for me: Try using the pseudo-variables. You'd set your variables in the language files to Code: $lang['validate_age'] = 'You must be {age} or older to complete this request.'; After that, you could write a very simple parser (if you need it constantly, make it a helper or plugin that you can autoload) to replace the variable: Code: function parse_line($var, $config_item, $lang_line) Code: $foo = parse_line('age', 'min_age', 'validate_age');
[eluser]Arjen van Bochoven[/eluser]
Why not use print_f: Code: $format = 'There are %d monkeys in the %s'; http://nl3.php.net/manual/en/function.sprintf.php Arjen
[eluser]Armchair Samurai[/eluser]
[quote author="Arjen van Bochoven" date="1192238367"]Why not use print_f:[/quote] Why not, indeed? I wasn't even aware of that function 'til now.... Thanks for that. It'd be too much work to clean up some past sites, but I'll be keeping this in mind for the future.
[eluser]Phil Sturgeon[/eluser]
You mean sprintf() surely? print_f() would have little use in a CI setup. |
Welcome Guest, Not a member yet? Register Sign In |