-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
front controller in subdirectory #86
Comments
Post a gist of your router code. |
hi @pmjones the dir layout is:
i have a setup with apache 2.2 fast-cgi php-cgi. with the same setup all other frameworks zf2, sf2, yii2, slim, flight and a couple of mine all recognize the directory relative to the webroot and i don't need to include it in route definitions, which makes the application more portable. thanks
|
I wonder if it's the .htaccess file. |
I just tried it here and it seems to work. Here was the process:
Browse to http://localhost:8080/foo/bar/baz/framework-project/web/index.php and I see "Hello World!". |
hi @pmjones I am quickly reading the router code. In my implementations i have routing components trying matches againt a request object (which provides the subdirectory part), while aura-routing (Route) seems to get that (isMatch()) parsing a $server parameter by itself, which i guess in non testing environment is the $_SERVER superglobal. i will look into it later, |
but the builtin web-server always has the working directory translated to a root "/" url, so it doesn't matter where the index.php is located as you usually run the server inside the directory it resides in. |
I'm starting the web-server multiple directories up, so there's no index in that directory. |
Hi @pine3ree , I have not heard such an issue before. I will try to replicate this. So if I am correct you are working with aura/web-project . Could you give a |
i just found this old post, not sure it still applies: http://elofson.ca/2013/10/mini-framework-with-aura/ The author adds the subdirecory in route definitions too. |
@pine3ree thanks for the link. Nice post also, never noticed it. It is not using the framework, but components only. But over all functionality is some what similar. One of the problem I could not figure is how we could replicate the issue. May be you could give the steps you did like .
Your virtual host points to |
hello again @harikt.
the 2/ dir has the 2.0 components anyway, i don't want to waste your time guys. thanks a lot! regards! |
The only thing I can suggest is to use |
@pmjones |
Hi @harikt steps
basically application surces live inside subdirs in a common folder
so the app/ directory name real meaning would be apps/, i just avoid plurals app entry points inside subdirs the vhost webroot
I always use this strategy when starting a new project so i can test suburl handling, features and response times, before deciding which framework to use. btw, in my request implementation i get the PATH_INFO virtual path or build one if not set in the php request environment, and pass it to the router component. Maybe this is the missing part? My components are not decoupled: the router depends on the request object, but before rewriting them i will wait for a definitive version of psr-7. |
Hi @pmjones @harikt , The webKernelRouter::getPath() works like this:
When the entry script is inside a subdir the subdir part will never get stripped unless you use the full entry script path, as @pmjones suggests, so, without using the script filename in the urls the router will never find a match unless the subdir is added as a prefix in all route definitions. i believe there are a couple of way of solving this:
|
hi @pmjones , could auraphp/Aura.Web_Kernel#30 be a valid (quick) fix? This PR is not to be merged as it is, as it uses a superglobal. Just as quick fix. I am not sure if it could break anything else in aura. If so, the script name could be retrieved adding a new key in Request\Url: $path = $this->request->url->get('script_name');
//...
/**
*
* @var array component constants, see http://php.net/parse-url
*
*/
protected $keys = array(
PHP_URL_SCHEME => 'scheme',
PHP_URL_HOST => 'host',
PHP_URL_PORT => 'port',
PHP_URL_USER => 'user',
PHP_URL_PASS => 'pass',
PHP_URL_PATH => 'path',
PHP_URL_QUERY => 'query',
PHP_URL_FRAGMENT => 'fragment',
'script_name' => 'script_name'
);
//...
protected function setParts($server)
{
$parts = parse_url($this->string);
if ($this->hostIsMissing($server)) {
$parts[PHP_URL_HOST] = null;
}
$this->parts = $parts;
$this->parts['script_name'] = $this->getScriptName($server);
}
//...
/**
*
* Get the $_SERVER['SCRIPT_NAME'] value.
*
* @param array $server A copy of $_SERVER.
*
* @return bool
*
*/
protected function getScriptName($server)
{
return isset($server['SCRIPT_NAME'])
? $server['SCRIPT_NAME']
: null;
} |
I just landed; at first glance this looks OK. I'll review further and comment or merge as appropriate. Thanks! |
@pmjones kind regards, |
I've been thinking about this, and @harikt had a related idea in PR #84 . There's a related issue, in that generated URLs need to have the prefix added to them. I propose adding a $prefix parameter to the Router constructor. This will be stripped from the incoming URL before matching, and added to generated URLs. That should allow explicit setup of the expected prefix, instead of implicitly calculating it. @pine3ree @harikt thoughts? |
Fixed in #96. |
I know this sounds silly....but
I cannot make the router to recognize urls when the index.php is inside a subdirectory.
I added the RewriteBase rule but still the router works only if I prepend the subdirectory in rooute definitions.
what am i missing?
The text was updated successfully, but these errors were encountered: