如何在TYPO3 extbase扩展控制器中打开文件?

时间:2017-03-15 19:11:40

标签: typo3 extbase typo3-extensions

我需要读取扩展控制器内部的文件,此处我的扩展密钥为16 03 2017 20:49:40.709:DEBUG [plugin]: Loading inlined plugin (defining framework:jasmine). 16 03 2017 20:49:40.712:DEBUG [plugin]: Loading inlined plugin (defining launcher:Chrome, launcher:ChromeCanary, launcher:Chromium, launcher:Dartium, test). 16 03 2017 20:49:40.712:DEBUG [plugin]: Loading inlined plugin (defining framework:@angular/cli, preprocessor:@angular/cli, webpackPlugin, preprocessor:webpack, middleware:webpackBlocker, preprocessor:sourcemap). 16 03 2017 20:49:40.712:DEBUG [plugin]: Loading inlined plugin (defining reporter:kjhtml). 16 03 2017 20:49:40.712:DEBUG [plugin]: Loading inlined plugin (defining reporter:coverage-istanbul). 16 03 2017 20:49:42.821:DEBUG [web-server]: Instantiating middleware 16 03 2017 20:49:42.829:DEBUG [reporter]: Trying to load reporter: kjhtml 16 03 2017 20:49:42.830:DEBUG [reporter]: Trying to load color-version of reporter: kjhtml (kjhtml_color) 16 03 2017 20:49:42.830:DEBUG [reporter]: Couldn't load color-version. 16 03 2017 20:50:26.799:DEBUG [preprocessor.sourcemap]: base64-encoded source map for /Volumes/EXT/Projects/bct/bct_admin/src/polyfills.ts 16 03 2017 20:50:26.872:DEBUG [preprocessor.sourcemap]: base64-encoded source map for /Volumes/EXT/Projects/bct/bct_admin/src/test.ts 16 03 2017 20:50:27.093:DEBUG [karma]: List of files has changed, trying to execute 16 03 2017 20:50:27.094:WARN [karma]: No captured browser, open http://localhost:9876/ 16 03 2017 20:50:27.196:DEBUG [watcher]: Watching "/Volumes/EXT/Projects/bct/bct_admin/src/polyfills.ts" 16 03 2017 20:50:27.197:DEBUG [watcher]: Watching "/Volumes/EXT/Projects/bct/bct_admin/src/assets" 16 03 2017 20:50:27.206:INFO [karma]: Karma v1.4.1 server started at http://0.0.0.0:9876/ 16 03 2017 20:50:27.206:INFO [launcher]: Launching browser Chrome with unlimited concurrency 16 03 2017 20:50:27.325:INFO [launcher]: Starting browser Chrome 16 03 2017 20:50:27.326:DEBUG [temp-dir]: Creating temp dir at /var/folders/jb/ckmrwnyj6sl2gqvbzq28l9x40000gn/T/karma-26134570 16 03 2017 20:50:27.327:DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/jb/ckmrwnyj6sl2gqvbzq28l9x40000gn/T/karma-26134570 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-device-discovery-notifications http://localhost:9876/?id=26134570 16 03 2017 20:50:29.444:DEBUG [web-server]: serving: /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma/static/client.html 16 03 2017 20:50:29.962:DEBUG [web-server]: serving: /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma/static/karma.js 16 03 2017 20:50:30.129:DEBUG [karma]: A browser has connected on socket slzc36ToAi1EBjsoAAAA 16 03 2017 20:50:30.330:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=slzc36ToAi1EBjsoAAAA 16 03 2017 20:50:30.330:DEBUG [proxy]: NOT upgrading proxyWebSocketRequest /socket.io/?EIO=3&transport=websocket&sid=slzc36ToAi1EBjsoAAAA 16 03 2017 20:50:30.441:DEBUG [web-server]: serving: /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma/static/favicon.ico 16 03 2017 20:50:30.478:INFO [Chrome 56.0.2924 (Mac OS X 10.12.3)]: Connected on socket slzc36ToAi1EBjsoAAAA with id 26134570 16 03 2017 20:50:30.479:DEBUG [launcher]: Chrome (id 26134570) captured in 3.272 secs 16 03 2017 20:50:30.479:DEBUG [karma]: All browsers are ready, executing 16 03 2017 20:50:30.480:DEBUG [karma]: Captured 1 browsers 16 03 2017 20:50:30.631:DEBUG [middleware:karma]: custom files null null 16 03 2017 20:50:30.631:DEBUG [middleware:karma]: Serving static request /context.html 16 03 2017 20:50:31.028:DEBUG [web-server]: serving: /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma/static/context.html 16 03 2017 20:50:31.705:DEBUG [middleware:source-files]: Requesting /base/src/polyfills.ts?f7f84cb0226c1ac1d1ea181f87f1b945c7b60bf5 / 16 03 2017 20:50:31.706:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/polyfills.ts 16 03 2017 20:50:31.706:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/respond.min.js?a38264053571de02291899eabf9ae749c9a1159c / 16 03 2017 20:50:31.706:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/respond.min.js 16 03 2017 20:50:31.721:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/polyfills.ts 16 03 2017 20:50:31.739:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/respond.min.js 16 03 2017 20:50:32.258:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/excanvas.min.js?ae4ce1a2bfb06c82653633191b04a8969a946b6b / 16 03 2017 20:50:32.258:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/excanvas.min.js 16 03 2017 20:50:32.258:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/jquery/dist/jquery.js?38e82b4f24bf9f7e678a1d69a4e635363ce711ab / 16 03 2017 20:50:32.258:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/jquery/dist/jquery.js 16 03 2017 20:50:32.258:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/raphael.min.js?4854da2d86626159d5015ed6ad6c142b70c2b370 / 16 03 2017 20:50:32.258:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/raphael.min.js 16 03 2017 20:50:32.271:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/excanvas.min.js 16 03 2017 20:50:32.290:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/jquery/dist/jquery.js 16 03 2017 20:50:32.303:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/raphael.min.js 16 03 2017 20:50:32.314:DEBUG [web-server]: serving: /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma/static/context.js 16 03 2017 20:50:32.314:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/js.cookie.min.js?c3a95779bcddbb0eff1aafece75a53295b01124e / 16 03 2017 20:50:32.314:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/js.cookie.min.js 16 03 2017 20:50:32.315:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine-html-reporter/src/css/jasmine.css?c9871b8538297ee2479a3223e4b1c8afaa94e162 / 16 03 2017 20:50:32.315:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma-jasmine-html-reporter/src/css/jasmine.css 16 03 2017 20:50:32.316:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/bootstrap/dist/js/bootstrap.js?3b965a36a6b08854ad6eddedf85c5319fd392b4a / 16 03 2017 20:50:32.316:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/bootstrap/dist/js/bootstrap.js 16 03 2017 20:50:32.336:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/js.cookie.min.js 16 03 2017 20:50:32.350:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma-jasmine-html-reporter/src/css/jasmine.css 16 03 2017 20:50:32.367:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/bootstrap/dist/js/bootstrap.js 16 03 2017 20:50:32.380:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/bootstrap-switch/dist/js/bootstrap-switch.js?4e734a9596dc5356c708a790e43f5e77db7c8f33 / 16 03 2017 20:50:32.381:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/bootstrap-switch/dist/js/bootstrap-switch.js 16 03 2017 20:50:32.381:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/bootstrap-select/dist/js/bootstrap-select.js?4ad010fe0b62b789365b76833c0008cc0b424618 / 16 03 2017 20:50:32.381:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/bootstrap-select/dist/js/bootstrap-select.js 16 03 2017 20:50:32.381:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/morris.js/morris.js?582e763141f9a6b1490ba8af9b37c7cd95255992 / 16 03 2017 20:50:32.381:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/morris.js/morris.js 16 03 2017 20:50:32.381:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/bootstrap-hover-dropdown/bootstrap-hover-dropdown.js?4a2a7ed5473af5b3561dcb25ec38c33315f775ce / 16 03 2017 20:50:32.382:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/bootstrap-hover-dropdown/bootstrap-hover-dropdown.js 16 03 2017 20:50:32.382:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/jquery-slimscroll/jquery.slimscroll.js?1988633067079e50c05ac4bf42eb59c97aa96992 / 16 03 2017 20:50:32.382:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/jquery-slimscroll/jquery.slimscroll.js 16 03 2017 20:50:32.382:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/jquery.blockui.min.js?4d1ff795d8ce96081c46af237b983b02f2b4536d / 16 03 2017 20:50:32.382:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/jquery.blockui.min.js 16 03 2017 20:50:32.396:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/bootstrap-switch/dist/js/bootstrap-switch.js 16 03 2017 20:50:32.424:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/bootstrap-select/dist/js/bootstrap-select.js 16 03 2017 20:50:32.438:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/morris.js/morris.js 16 03 2017 20:50:32.453:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/bootstrap-hover-dropdown/bootstrap-hover-dropdown.js 16 03 2017 20:50:32.477:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/jquery-slimscroll/jquery.slimscroll.js 16 03 2017 20:50:32.490:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/jquery.blockui.min.js 16 03 2017 20:50:32.525:DEBUG [middleware:source-files]: Requesting /base/src/assets/cmp/bootstrap-table/dist/bootstrap-table.js?da9fd91cafbd5df4c88707484c02e699cde2417f / 16 03 2017 20:50:32.525:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/bootstrap-table/dist/bootstrap-table.js 16 03 2017 20:50:32.525:DEBUG [middleware:source-files]: Requesting /base/src/assets/js/echo.js?27e50d3d619606d504dea199d017743337e0cc43 / 16 03 2017 20:50:32.525:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/assets/js/echo.js 16 03 2017 20:50:32.525:DEBUG [middleware:source-files]: Requesting /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?916005cc407925f4764668d61d04888d59258f5d / 16 03 2017 20:50:32.526:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/node_modules/jasmine-core/lib/jasmine-core/jasmine.js 16 03 2017 20:50:32.526:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/boot.js?945a38bf4e45ad2770eb94868231905a04a0bd3e / 16 03 2017 20:50:32.526:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma-jasmine/lib/boot.js 16 03 2017 20:50:32.526:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/adapter.js?7a813cc290d592e664331c573a1a796192cdd1ad / 16 03 2017 20:50:32.526:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma-jasmine/lib/adapter.js 16 03 2017 20:50:32.526:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine-html-reporter/src/lib/html.jasmine.reporter.js?4af523ab7bfaa86c4966fa332c4dc2bd2278b4cc / 16 03 2017 20:50:32.526:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma-jasmine-html-reporter/src/lib/html.jasmine.reporter.js 16 03 2017 20:50:32.538:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/cmp/bootstrap-table/dist/bootstrap-table.js 16 03 2017 20:50:32.558:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/assets/js/echo.js 16 03 2017 20:50:32.579:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/node_modules/jasmine-core/lib/jasmine-core/jasmine.js 16 03 2017 20:50:32.599:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma-jasmine/lib/boot.js 16 03 2017 20:50:32.622:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma-jasmine/lib/adapter.js 16 03 2017 20:50:32.642:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma-jasmine-html-reporter/src/lib/html.jasmine.reporter.js 16 03 2017 20:50:32.700:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine-html-reporter/src/lib/adapter.js?9d2c71b931979c6194d209809111ee3a72cf149b / 16 03 2017 20:50:32.700:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma-jasmine-html-reporter/src/lib/adapter.js 16 03 2017 20:50:32.701:DEBUG [middleware:source-files]: Requesting /base/src/test.ts?8cc3132c0dad1642b9cf3246e9b897d644110f61 / 16 03 2017 20:50:32.701:DEBUG [middleware:source-files]: Fetching /Volumes/EXT/Projects/bct/bct_admin/src/test.ts 16 03 2017 20:50:32.714:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/node_modules/karma-jasmine-html-reporter/src/lib/adapter.js 16 03 2017 20:50:32.732:DEBUG [web-server]: serving (cached): /Volumes/EXT/Projects/bct/bct_admin/src/test.ts Chrome 56.0.2924 (Mac OS X 10.12.3) ERROR You need to include some adapter that implements __karma__.start method! Chrome 56.0.2924 (Mac OS X 10.12.3) ERROR You need to include some adapter that implements __karma__.start method! ^C16 03 2017 20:51:57.831:DEBUG [launcher]: Disconnecting all browsers 16 03 2017 20:51:58.470:DEBUG [launcher]: Process Chrome exited with code 0 16 03 2017 20:51:58.471:DEBUG [temp-dir]: Cleaning temp dir /var/folders/jb/ckmrwnyj6sl2gqvbzq28l9x40000gn/T/karma-26134570 16 03 2017 20:51:58.509:DEBUG [launcher]: Finished all browsers ,我要打开的文件是myext_key中的JSON文件data.json目录。我的研究告诉我,打开文件的最佳方式不是Resources/Private/JSON,而是file_get_contents($path)

所以我尝试使用以下代码,但这不起作用:

\TYPO3\CMS\Core\Utility\GeneralUtility::getURL($path)

感谢您的帮助!

1 个答案:

答案 0 :(得分:5)

不确定file_get_contents()是否有任何问题,而不是内存含义,因为file_get_contents()基本上会为整个文件内容分配一个变量。只要你处理一个小的.json文件很小就应该放在安全的地方。

获取扩展目录中文件的绝对文件名的方法是getFileAbsFileName()

$content = file_get_contents(
    \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:myext_key/Resources/Private/JSON/data.json'
);