Posted on | April 5, 2012 | 1 Comment
You’re developing a huge application, but want your code to be modular so that you can use it again else where. But what happens if one module is dependent on another, and you have forgotten to include it?
For example, you may have a ‘products’ module that allows you to add, edit, and view products. Later you decide you want to start selling these so create an ‘ecart’ module. In a later application you install the ecart module but not the products module, and wonder why it doesn’t work…
This bit of code will check if the dependent module is available to the application.
Place this code in the bootstrap file of in the ecart module. You do not need to call this function, your Zend Framework application will call every _init* function in your bootstrap file.
$modules = array_keys($dirs);
if (!in_array(‘products’, $modules))
throw new Zend_Exception(‘Required Module “Products” not installed.’);
Posted By:Richard Parnaby-King