my url is http://localhost/myAppliation/....
I want to get the "myApplication". Which is the key word to get the value?
my url is http://localhost/myAppliation/....
I want to get the "myApplication". Which is the key word to get the value?
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];
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.
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.
http://book.cakephp.org/view/317/Cake-s-Global-Constants-And-Functions
I think you want to use the WEBROOT_DIR constant.