tags:

views:

67

answers:

4

my url is http://localhost/myAppliation/....

I want to get the "myApplication". Which is the key word to get the value?

A: 

Edit: Didn't see that you were using CakePHP. If you weren't using any frameworks, you would get the path via this:

First you need to reconstruct the URL.

$pageURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
if ($_SERVER["SERVER_PORT"] != "80")
{
    $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} 
else 
{
    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}

Then parse it for the path.

$parts = parse_url($pageURL);
$path = $parts['path'];

After that if you want to only get the first path, explode it on '/', strip out the null values, and then the first one will be the first path, and so on.

$paths = explode('/', $path);
foreach($paths as $key => $value)
{
    if(!empty($value))
    {
        $new_paths[] = $value;
    }
}
$first_path = $new_paths[0];
Chacha102
You have to do all that to get the name of your application? Surely it's stored somewhere.
Robert Harvey
Thats for breaking up the path. If you are using a framework, you never mentioned it.
Chacha102
Ah .. never saw the cakephp part. You should mention that in the question. I'll make it clear that mine is for breaking up the path since I don't know much about CakePHP.
Chacha102
A: 

There is something called the $Name attribute, but I'm not sure if that gives you the application name. The CakePHP manual says:

PHP4 users should start out their controller definitions using the $name attribute. The $name attribute should be set to the name of the controller. Usually this is just the plural form of the primary model the controller uses. This takes care of some PHP4 classname oddities and helps CakePHP resolve naming.

http://book.cakephp.org/view/52/name

Robert Harvey
+1  A: 

I think you want:

$this->webroot

or

$this->base

or

$this->here

in your controller. See http://api.cakephp.org/class/controller for definition of this variables.

niteria
A: 

http://book.cakephp.org/view/317/Cake-s-Global-Constants-And-Functions

I think you want to use the WEBROOT_DIR constant.

Jesse Kochis