I'm using following code within the cakephp project in bootstrap to define constants like webroot path. Could it be right

$_ROOTPATH  = strtolower('http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
$URLPART    = explode('cake',$_ROOTPATH);

  1. ROOTPATH instead of $this->webroot .
  2. DOCUMENTROOTPATH pointing to actual to piont towards the actual path as with /var/www/

Exactly what do you say relating to this. Any note/suggestion is welcome.

Why don't you use $_SERVER['DOCUMENT_ROOT']

you do not need no variable to obtain a webroot. it is usually just /. Very handy.

Regarding file pathways, perhaps you have checked out the present core constants? You'll most likely find the majority of the file path constants you'll need happen to be defined there.

For instance, your DOCUMENTROOTPATH is exactly like (In my opinion) the WWW_ROOT constant.

For Web addresses, CakePHP's Router::url() takes proper care of handling all Web addresses inside a consistent manner (eg. Web addresses output by Controller::redirect(), FormHelper, HtmlHelper, etc.)

You may also call Router::url() statically wherever you have to create Web addresses:

echo Router::url('/some/random/path');
// output: http://www.example.com/path/to/cake/some/random/path
echo Router::url(array('controller' => 'abc', 'action' => 'xyz'));
// output: http://www.example.com/path/to/cake/abc/xyz

Unless of course I'm missing something, I'd only use the above mentioned rather than littering the application with the kind of ROOTPATH and RESOURCEBASEPATH. For instance the next approaches are equivalent:

$this->redirect(ROOTPATH . 'some/place'); // your way
// takes you to: http://www.example.com/path/to/cake/some/place
$this->redirect('/some/place'); // cake way
// takes you to: http://www.example.com/path/to/cake/some/place

echo $this->Html->image(RESOURCEBASEPATH . 'some/image.jpg'); // your way
// outputs: <img src="http://www.example.com/path/to/cake/resources/some/image.jpg" />
echo $this->Html->image('some/image.jpg'); // cake way
// outputs: <img src="http://www.example.com/path/to/cake/img/some/image.jpg" />
echo $this->Html->image('../resources/some/image.jpg'); // cake way
// outputs: <img src="http://www.example.com/path/to/cake/resources/some/image.jpg" />

I'm by using this (presuming that i'm within the right folder using the file that i'm penning this code in):

$path = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;