On Wed, Mar 11, 2009 at 12:44 PM, Shawn McKenzie <nos...@mckenzies.net> wrote:
> Clancy wrote:
>> It is my understanding that when you open a page the PHP server looks for 
>> index.php in the
>> site root directory, and loads it. As a result the working directory of the 
>> page will be
>> the root directory of the site.  I have always worked on this assumption, 
>> and it has
>> always been correct.  On the other hand Stewart thinks that I cannot rely 
>> this, and am
>> likely to get into trouble as a result.
>> Are there any systems in which my assumption will not be correct?
> In many frameworks this assumption is not correct.  I am using the
> default CakePHP layout as an example.
> Depending on your terminology, your DocumentRoot is /var/www/ and in
> this case is also the filesystem path of your site's root dir, however
> the sites root dir in a URL is /.
> Consider the CakePHP structure:
> /var/www/
>  .htaccess
>  index.php
> /var/www/webroot
>  index.php
> If you browse to http://example.com/ (in most cases), one of 2 things
> happens:
> 1. The webserver opens the /var/www/.htaccess and according to the
> rewrite rules there it rewrites to /var/www/webroot/.  So any getcwd()
> would be /var/www/webroot/
> 2. If not using modrewrite, the web server looks for index.html and then
> index.php in /var/www/ which has a require for webroot/index.php.  So
> any getcwd() would be /var/www/.
> Consequently, CakePHP and the other frameworks that I've seen use
> basename() and dirname() in conjunction with __FILE__ to define the
> paths/relative dirs within the app.

Come to think of it, this may very well be true for all MVC frameworks
(unless the models, views, and controllers are all in the same
directory as the launch script). I can at least vouch for the fact
that CodeIgniter, like CakePHP, will fudge your directory estimation
if you're expecting getcwd() to be right.

// Todd

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to