开发者

Basic file operations in CakePHP?

开发者 https://www.devze.com 2023-02-12 07:58 出处:网络
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 framewor

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:

  • What is the preferred way to interact directly with files? Through a datasource, direct PHP or someway else?
  • Where should files like these be located? In the /vendors/ dir? Outside the CakePHP app?
  • Is there a fancy component/behavior to do this?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号