Understanding Autoloading, Helper Classes and Helper Functions

Comparing #7 with #8

Revision #8 was created by Steve Friedl Steve Friedl on Aug 10, 2011, 3:42:50 PM.

Renamed helpers.inc to helpers.php

Content

[...]
```
but this is tedious: it's much more convenient to use regular ordinary functions to do this, and it's easy to achieve in Yii (though it does not involve the autoloader).

### 1. Create helpers function file

I usually define helpers in `protected/components/helpers.
incphp`: ```php <?php // protected/components/helpers.incphp

function startsWith($needle, $haystack)
[...]
// protected/config/main.php

require_once( dirname(__FILE__) . '/../components/helpers.
incphp');

...
```
This done, any part of the application can use the helper functions defined here:
[...]