Friday, October 29, 2010

Publishing to alternate assets directory

Sometimes, it's not possible to use the standard 'assets' directory for publishing assets. After struggling with this for a while, I discovered that the solution is, as is typical with Yii, even simpler than I could have hoped for.

To use an alternate directory for publishing your assets, you simply need to do these two steps:

1)Ensure the directory you wish to publish to exists and is writable by the web application.
2) Add a configuration entry for the assetManager in your main config file within the components section:
'assetManager'=>array(
'basePath'=>'fullbasepath'.DIRECTORY_SEPARATOR.'alternateDirectoryName',
'baseUrl'=>DIRECTORY_SEPARATOR.'alternateDirectoryName',
),

That's it. I had found the basePath pretty early on, but I didn't realize that you need to alter the publishing path AND the url to keep them pointed to the same location. It doesn't do that automatically. ;)