2013-10-14 116 views
0

需要將數據保存到文本文件中。無法獲得正確的文本文件路徑。請建議。Symfony中的URL路徑

現在,我通過使用此代碼$file_url= "{{ asset('/temp_files/calender.txt') }}"; $ourFileHandle = fopen($file_url, 'w') or die("can't open file1");

,但沒有得到確切的路徑嘗試。

+0

你究竟在哪裏試圖執行該代碼?在你的控制器? – nifr

回答

0

使用templating.helper.assets,像這樣

$this->container->get('templating.helper.assets')->getUrl('bundles/somename/other/calendar.txt') 

凡束/ somename在您的網頁存在/捆綁文件夾中。如果你沒有在您的網頁/文件夾的包有什麼,然後運行以下命令:

php app/console assets:install ./web --symlink 

上面列出的其他文件夾將是一個你創建你的包的資源/公用文件夾。