lets say we have a dir
script.php is a class that is extending a controller class from index.php,
application/helloworld/script.php
index.php
is there a way to return the folder helloworld from index.php ( controller ) ?
edit*
script.php
class Helloworld extends Controller
{
function __construct()
{
echo 'helloworld';
}
}
index.php
class Controller
{
function wherethescript(){
# trying to find folder where helloworld.php is in from this class
}
}
include_once 'application/helloworld/helloworld.php';
$x=new Helloworld;
$x->wherethescript();
If you have any path,
basenamewill get you the last part of it.dirnamechops off the last part. The__FILE__constant contains the path of the current file. So something likebasename(dirname(__FILE__))inscript.phpshould do.That can be shortened to
basename(__DIR__)in PHP 5.3 and up.If you want to do this from
index.phpand notscript.php, you can reflect on the object to get where it was defined: