PHP files can be require to each other. But if the nested directory is deep, is there any good solution? For example: {code ...} in such a directory, if you need to introduce hook in test2, It is very troublesome to find the directory. It can be done if the cross-file global variable is used ,... PHP files can be require to each other. But if the nested directory is deep, is there any good solution?
For example:
/--root|_lib| |_hook.php|_src|_view| |_page| |_js| |_img|_handler |_test1 |_test2 |_test2.php
In such a directory, if you need to introduce hook in test2, It is very troublesome to find the directory. You can do this if there are too many files, cross-global variables must be used in each file, which may be messy. Can I define the directory structure in a single file and provide it to other files? How can we implement this change?
Thank you for your answers!
Reply content:
PHP files can be require to each other. But if the nested directory is deep, is there any good solution?
For example:
/--root|_lib| |_hook.php|_src|_view| |_page| |_js| |_img|_handler |_test1 |_test2 |_test2.php
In such a directory, if you need to introduce hook in test2, It is very troublesome to find the directory. You can do this if there are too many files, cross-global variables must be used in each file, which may be messy. Can I define the directory structure in a single file and provide it to other files? How can we implement this change?
Thank you for your answers!
Http://www.php-fig.org/psr/psr-0/
I immediately thought of the underline name.
new Path1_Path2_Path3()
Equal to Path1/Path2/Path3.php
Include require.
Thinkphp has a namespace usage. For more information, see
You can write a function by yourself. The function is used to load the required files. When you need to introduce a file, traverse the directory to find the file. However, the efficiency is relatively low.
We recommend that you use constants or namespaces)
We recommend that you use a streamlined Router database as the routing controller handler and hook. You can use hook to easily customize parameter filtering and login check.
(new Router())->error(405, function($message){ header('Location: /hello/world', true, 302);})->get('/hello/:name', function($name){ echo "Hello $name !!!";})->execute();