答案 0 :(得分:8)
您可以从控制器执行此操作:
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOException;
//Define your file path based on the cache one
$filename = $this->container->getParameter('kernel.cache_dir') . '/yourapp/filename.txt';
//Create your own folder in the cache directory
$fs = new Filesystem();
try {
$fs->mkdir(dirname($filename));
} catch (IOException $e) {
echo "An error occured while creating your directory";
}
//Write your file
file_put_contents($filename, 'Text content');
//Read the content of your file
echo file_get_contents($filename);
答案 1 :(得分:3)
请注意,现在建议使用DoctrineCacheBundle。不要被学说品牌所误导 - 这与ORM和DBAL等区别开来。
答案 2 :(得分:0)
不确定您要实现的目标,但是您可以查看配置组件文档,特别是在ConfigCache类中:
http://symfony.com/doc/current/components/config/index.html
http://symfony.com/doc/current/components/config/caching.html