Distributing CakePHP Apps: Handling your cake with care
As I mentioned in my last post, I’ll be detailing some of the challenges we have faced since porting SlideShowPro Director to the CakePHP framework.
One of the first things I wanted to do was move the core cake library inside the app folder, just to make the directory structure a little cleaner. One of the most difficult parts of distributable apps is the upgrade process, so if we could keep everything inside one folder, it would go a long way toward making upgrading an existing install idiot-proof.
The default Cake structure is pretty clean as it is. It consists of 4 folders and an index.php file. Immediately we could get rid of the docs folder, as we do not need to distribute that with our app. Also, the vendors folder isn’t needed either, as we are not including anything via vendors (and if we were I assume we could use the vendors folder in app/). So now we are left with app, cake and index.php. Since index.php really doesn’t change that much (it is basically a passthrough file to handle servers who do not have mod_rewrite installed), if we could just get the cake folder inside of the app folder, we would have a super clean structure.
After rooting around for a while, I finally found this little gem in app/webroot/index.php:
This is the code that lets Cake know where the core resides. By default, it looks for it in ROOT, which is defined as the root folder of your application (where app, cake and index.php reside, remember?). So, if we want to move it inside the app folder, the change is quite simple:
-
}
Walla. Cake will now look for its’ core folder inside of app, instead of in the root folder. Now we have accomplished what we set out to do, as our main application folder now only contains index.php and the app folder (along with your .htaccess file, if you are so inclined).
UDPATE: You will also need to make the above changes in the index.php file found in the root folder (if you are supporting users who do not have mod_rewrite installed).
One more little tip we just learned recently. As CakePHP grows in popularity, some hosts are now including installations on their servers, usually in some central location like /usr/share/pear that is a part of the include_path in PHP. That’s all well and good, except that the centrally installed Cake will be loaded first (and therefore be used) instead of the Cake you have installed in your app folder. To understand why, take a look at this line (again from app/webroot/index.php):
You’ll notice we are appending our folders to the end of the include_path, meaning anything found centrally will override our stuff. To remedy this, we’ll prepend our directories to the include_path instead:
That way, the Cake bundled with your application will be used first and foremost, which is good since it is the version you know works with your app. Also, we’ve removed the reference to ROOT . DS . APP_DIR since that is exactly the same as CAKE_CORE_INCLUDE_PATH in our case. Lastly, you also will note that this edit is below the big “DO NOT EDIT BELOW THIS LINE” comment, but sometimes you just have to get your hands dirty ![]()
Happy baking!