laander
laander

Reputation: 2663

Basic file operations in CakePHP?

this should be insanely obvious but we're having a hard time figuring out how do this probably.

In PHP, writing and reading from files are simple matters. However, as we use CakePHP as our framework, we'd like to do this the CakePHP way. Take this scenario for example:

Gitosis, a self-hosted git repository platform, has a gitosis.conf file that contains simple setup for permissions, users and reps. We'd like to read and, more importantly, manipulate the data in this file, through CakePHP. Questions:

Upvotes: 2

Views: 639

Answers (2)

JohnP
JohnP

Reputation: 50019

Using a model to interact with the config file is a good idea. That way the code can be used in multiple controllers without an issue. As for a place to keep it, in our CakePHP projects, we usually have a data folder inside apps to keep all app specific data stored.

Upvotes: 3

runsnbunsn
runsnbunsn

Reputation: 31

Cakephp has it's own file class, more info here: http://api.cakephp.org/class/file

I would use this class to interact with files, you could also inherit your own class from the file class so you can add your own methods too.

Adding to vendors dir is possible of course but I think it's not necessary.

There may be components which handle the file operations, but I think the file class is enough for most purposes.

Upvotes: 3

Related Questions