5
I’d like to know how to use the path
in a procedural system, the correct way to define the/the paths, and to access the files, and what is most important to know about. Researching I found more examples in OOP, and I found nothing here on this subject.
I’m using ../
, and sometimes ../../../../
Rsrs then I think it’s time to fix it.
I know I can use define
, but I was left in doubt of where to include, and I did not quite understand the functioning of DIRECTORY_SEPARATOR
, and the options. In this question in the OS, has several paths defined, not just the root, and I want to know, using the procedural system, how do I use this. Create a file with all these rules for each directory? How to access these directories later?
I will post an example of using the path
to generate an error log (which was used in this answer) and if someone were willing to explain the details, I think it would be interesting to illustrate the functioning.
ini_set('error_log', BASE_DIR . DIRECTORY_SEPARATOR . 'logs' . DS . 'php' . DIRECTORY_SEPARATOR . 'PHP_errors-' . date('Ym') . '.log');
Which version of php are you using? There are some things that simplify
– rray
version 5.5.4 @rray
– gustavox
My suggestion is similar to that of Soen, define a file with only constants, the first of them the root(
ROOT_PATH
) of the project, if you need can create other,TEMPLATE_PATH
,LIB_PATH
etc..– rray
Difference between PATH_SEPARATOR and DIRECTORY_SEPARATOR
– rray
And then what do I call it in the project files? I make a
include
in each file that will use the path? Or can I put theinclude
only in connection file for example? Does not roll an answer? : -) Thanks.– gustavox
Each file you use will need include. Ai calls the constants straight.
include 'LIB_PATH/funcoes/data.php';
.– rray