Propel: problem with loading configuration variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Propel: problem with loading configuration variables

Post by raghavan20 »

The Propel.php has a public static method to load configuration files into the static variable: $configuration

it uses a include line which will actually load an array from a configuration file which is actually returned.
but this line does not work as expected here in php.net example

Code: Select all

return.php
<?php

$var = 'PHP';

return $var;

?>

noreturn.php
<?php

$var = 'PHP';

?>

testreturns.php
<?php

$foo = include 'return.php';

echo $foo; // prints 'PHP'

$bar = include 'noreturn.php';

echo $bar; // prints 1

?>
the config file

Code: Select all

<?php

// This file generated by Propel convert-props target on Tue Nov 14 16:33:05 2006
// from XML runtime conf file /var/www/test/bookstore/runtime-conf.xml [EDITED]
return array (
  'log' => 
  array (
    'ident' => 'propel-bookstore',
    'level' => '7',
  ));

?>
the line that calls the following code

Code: Select all

Propel::init( '/var/www/test/bookstore/build/conf/bookstore-conf.php' );
the actual code in Propel.php file

Code: Select all

public static function configure($configFile)
	{
		self::$configuration = include($configFile);
		
		if (self::$configuration === false) {
			throw new PropelException("Unable to open configuration file: " . var_export($configFile, true));
		}
	}
so in the above function, configFile is the path to the configuration file.
when it executes the include line, it does not move to the next line in the function and no error is reported as well.

i do see that line can be

Code: Select all

include $configFile instead of include($configFile) and I have tried the other format but it does not work.
Any ideas why return is not working...
Last edited by raghavan20 on Tue Nov 14, 2006 11:13 am, edited 2 times in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: Propel: problem with loading configuration variables

Post by volka »

raghavan20 wrote:$foo = include 'return.php';

echo $foo; // prints 'PHP'
And that's what you want. The version with the return statement is the one you want to use.
But you don't
raghavan20 wrote:the config file

Code: Select all

<?php

// This file generated by Propel convert-props target on Tue Nov 14 16:33:05 2006
// from XML runtime conf file /var/www/test/bookstore/runtime-conf.xml
$configArray = array (
  'log' => 
  array (
    'ident' => 'propel-bookstore',
    'level' => '7',
  ));

?>
there's no return $configArray. Why?
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

sorry, i was doing a workaround earlier and now i have put the original configuration file in...thanks volka
Post Reply