Autoloading Yii application classes in external scripts

Notice: This post is more than a year old. It may be outdated.

Sometimes I want to have access to all of my classes in a Yii app externally. For example, I would like to run an external PHP script with cron and I would like to use my application classes. To achieve that, I created a separate classloader file.


// change the following paths if necessary
$composer = dirname(__FILE__) . '/../vendor/autoload.php';


This creates a Yii console application and in addition autoloads all classes managed by Composer. Now you can use your application classes for example in a cron script.

comments powered by Disqus