Relative paths and migrations

I’m using a relative paths for copy/move operations on files, like (with proper folder creation, if necessary):


When I’m using such paths in website (in controller’s action), everything seems fine (to me) and files lands in “uploads” dir in root directory folder (where it is expected.

I have just found (to my surprise), that if I use the very same path in a migration, files will be put to "uploads" dir created in "protected" folder.

Is this some kind of bug or a wanted behaviour (i.e. "protected" folder is root folder for migrations)?

According to the doc, migration is supposed to be executed in the "protected" directory.

So, probably you can make your application root directory the current directory of your command.

$ cd path/to/your/app

$ protected/yiic migrate ...

I’m not sure if it works or not though.

But IMO it’s better not to rely on the current directory which may vary according to the context when you specify a directory name or a file path in a script. You’d better either use an absolute path or change directory to a base directory using an absolute path before using a relative path.

cp /path/to/the/source/file /path/to/the/destination/file

# or

cd /path/to/the/base/directory

cp relative/path/to/source/file relative/path/to/destination/file