Last week I introduced an optional feature to the OpenID component: if you want to use that feature you have to place a library in a certain folder. If there is no such library, the feature is not active.
In plain PHP you could implement such a solution in the following way:
if (file_exists('path_to_library_file')) {
include('path_to_library_file');
use_library_function();
}
In CakePHP, we usually use App::import() to load files. And as this method returns false if it can’t load the specified file, we can rewrite the snippet from above to:
if (App::import('Vendor', 'library', array('file' => 'path_to_library_file'))) {
use_library_function();
}
Not really earth-shattering, but maybe it is helpful for some of you ;)
[…] public links >> loading Loading optional functionality First saved by rikhard | 1 days ago COMIC IS LOADING First saved by spite | 4 days ago […]
… [Trackback]
[…] Read More: cakebaker.42dh.com/2008/08/11/loading-optional-functionality/ […]
…For further Information click here
[…]I am no longer certain the place you’re getting your information, but great topic.[…]
…Links
[…]Wow, marvelous weblog layout! How long have you been blogging for?[…]
…Visitor recommendations
[…]Nice blog here! Also your website a lot up fast![…]