How to use the File class from the core
You may have noticed that there exists a File class in the core (cake/libs/file.php). But how can you use it? Let me give you a simple example:
// app/controllers/test_controller.php
// includes cake/libs/file.php
uses('file');
class TestController extends AppController
{
var $uses = null;
function index()
{
$f = new File(TMP.'test.txt', true);
$f->append('hello');
exit;
}
}
In a similar way you can use the other classes available in the cake/libs folder in your application.




Very useful, thanks!
Yep, pretty useful. Simple but not discovered yet :)
I am glad it is useful for you :)
Very helpful in keeping the code CakePHP. Also, the Folder create and search functionality is a lot more wow than the File. But both are mighty helpful to have.
Thanks so much for documenting this. Cake’s documentation is a little sparse on core class featurs like this, which are really handy for, eg. writing temporary files.
@MJ: Cool to hear it is useful for you, thanks :)