|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
macx333 Smarty n00b
Joined: 31 May 2003 Posts: 1 Location: Flagstaff, AZ
|
Posted: Sat May 31, 2003 7:57 pm Post subject: Multiple hidden config blocks in single config file |
|
|
Multiple hidden config blocks in single config file do not work.
Try:
[php:1:f5d4edff46]<?php
require_once("Smarty.class.php");
$foo = new Smarty;
...
//stuff for configuration here
...
$foo->config_load('config_file.conf');
echo $foo->get_config_vars('bar0') . "\n<br>";
echo $foo->get_config_vars('bar1');
?>[/php:1:f5d4edff46]
with config file:
Code: | [.block0]
bar0 = "slashdot.org"
[.block1]
bar1 = "fark.com"
|
My experience is that bar0 will be output properly, but bar1 will not. changing '.block0' to 'block0' makes it work; hence, multiple hidden blocks in a single config file do not work.
Am I crazy, or is this a bug?
-s |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Jun 01, 2003 5:13 am Post subject: |
|
|
I would call that a bug! Good Find!
None of the hidden sections should be loaded by config_load. I checked this directly against the Config_File class and got the same results. Interestingly, if you have items in the global section, it does not exhibit this behaviour.
Modifying your example slightly:[php:1:b0076e9396]
$conf = new Config_File( $smarty->config_dir );
$data = $conf->get( 'config_test.conf' );
print_r($data);[/php:1:b0076e9396]produces the incorrect: Quote: | Array ( [bar0] => slashdot.org ) | while Code: | bar = "global bar"
[.block0]
bar0 = "slashdot.org"
[.block1]
bar1 = "fark.com" | produces the correct: Quote: | Array ( [bar] => global bar ) |
These also work as expected:[php:1:b0076e9396]$data = $conf->get( 'config_test.conf', 'block0' );
$data = $conf->get( 'config_test.conf', 'block1' );[/php:1:b0076e9396]
This problem is not limited to hidden sections but appears to happen for any section that is not proceeded by at least one blank line, comment line or global item. So this works correctly: Code: |
[.block1]
bar0 = "slashdot.org"
[.block0]
bar1 = "fark.com" |
The fix (errr, hack) is easy enough: Code: | Index: libs/Config_File.class.php
===================================================================
RCS file: /repository/smarty/libs/Config_File.class.php,v
retrieving revision 1.48
diff -u -r1.48 Config_File.class.php
--- libs/Config_File.class.php 8 May 2003 14:29:44 -0000 1.48
+++ libs/Config_File.class.php 6 Jun 2003 04:32:54 -0000
@@ -259,6 +259,7 @@
$contents = preg_replace('!\r\n?!',"\n",$contents);
}
+ $contents = "\n$contents";
$config_data = array();
/* Get global variables first. */
|
I only tested 2.5.0 but I don't think this would have changed since then. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Jun 06, 2003 1:52 pm Post subject: |
|
|
This is fixed in CVS. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|