0
votes

I'm learning Zend Framework 2 and I'm trying to connect to ldap using the info here: http://framework.zend.com/manual/2.0/en/modules/zend.authentication.adapter.ldap.html.

This line is returning false: $configReader->fromFile('foo.ini')

Looking into the source Zend\Config\Reader\Ini is_file() is returning false. I've chmoded the entire entire app to 777 just so permissions are not an issue.

I set up a test which you can see here:

app/public/ldapconfig.ini
app/public/isfiletest.php
--- var_dump(is_file('ldapconfig.ini')); (true)

app/module/Foo/src/Foo/Model/ldapconfig.ini
app/module/Foo/src/Foo/Model/Bar.php
--- var_dump(is_file('ldapconfig.ini')); (false)

The last line of the code above is in a public function that is being called by the controller. Any ideas why there is a difference in behavior?

2

2 Answers

0
votes

I'm not sure how Zend framework is set up but I think when you exec the code the root path is different

try

var_dump(is_file('../module/Foo/src/Foo/Model/ldapconfig.ini'));

or

var_dump(is_file('./ldapconfig.ini'));
1
votes

For clarification to Ards answer:

Everything within ZF2 is based off of the Projects ROOT Path. This is done at public/index.php using chdir(dirname(__DIR__));. This means that every future include is based off of the projects ./

Furthermore i suggest following best practices and place the config file into the config folder ./module/Foo/config/ldapconfig.ini. This makes much more sense than placing a configuration file into the models sources ;)

One last note: INI-parsing (as done in ZF1) is much less slower than is ZF2-Style (or rather basic PHP) Arrays ;) You might want to switch back to the basics, too.