Return $path
at the end of its function. Local variables (those declared within the function) are not accessible in other parts of the code.
You can define an associative array with the directories, and pay the desired part by informing an argument in the function
function base_url($selecionado){
$dir = ['imagem' => '/imagem/', 'js' => '/js/', 'css' => '/css/'];
return $dir[$selecionado];
}
//chamada:
echo base_url('css');
Another option is to create a file with constants of the most important directories and import it in the other files.
cofing.php
<?php
define('ROOT_DIR', dirname(__FILE__));
define('FUNCTIONS_DIR', ROOT_DIR .DIRECTORY_SEPARATOR. 'functions');
define('IMG_DIR', ROOT_DIR .DIRECTORY_SEPARATOR. 'www' .DIRECTORY_SEPARATOR. 'img');
define('CSS_DIR', ROOT_DIR .DIRECTORY_SEPARATOR. 'www' .DIRECTORY_SEPARATOR. 'css');
On the other pages, do a include/require for config.php
, stay tuned to define the ROOT_DIR
in this example I started from the point that it is at the root of the project.
index php.
<?php
include_once 'config.php';
echo 'Raiz do projeto: '. ROOT_DIR . '<br> imagens: '. IMG_DIR;
<img src="<?php echo IMG_DIR.'/logo.jpg'" />
It seems that it is not clear to you the concept of function: they must do something, and generally return something. This function of yours doesn’t do either! The variables you create inside only exist inside yourself.
– bfavaretto
You need to edit the question again, now there is no variable called
path
got even weirder O.o– rray
@bfavaretto has some function in the stack to return the question to initial form?
– Marcos Vinicius
Click on the link "edited XX min ago" will open the editing history, go to the editing you want to go back and click on "revert".
– rray