We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How read/write file from app directory

Hello, I cannot access a file.
Path to file: /app/resources/cities.txt

I'm trying use in indexController (indexAction)
return file_put_contents("cities.txt", $string);

I tried this path: /app/resources/cities.txt, /resources/cities.txt, resources/cities.txt, and cities.txt

How I can access this file?

edited Jul '14

Maybe this way, but it's a big hack:

$dir = dirname(__FILE__);
file_put_contents($dir."/../resources/cities.txt", $string);

Better solution is if you define main dirs in your config, and than you use that...

edited Jul '14

Thank you, for the answer. How can I use the $config variable in controller? Set in DI?