If I am building a module and put a folder called lib with some classes in it, will they be automatically included?
Any suggestions on how to make the methods available to other modules?
Question on how to make a module with an API
Re: Question on how to make a module with an API
No.kendo451 wrote: If I am building a module and put a folder called lib with some classes in it, will they be automatically included?
You need to include them by yourself.
What about creating a function that includes the class file? And one function to access certain functions of that class? Here an example...kendo451 wrote: Any suggestions on how to make the methods available to other modules?
Lets say you have two modules. ModuleA and ModuleB.
ModuleA has some classes that should be used by ModuleB.
So in ModuleA you can create a function to load the class and one function to access the classes methods:
Code: Select all
var $ClassA;
var $ClassB;
var $ClassC;
function LoadClass($className, $someVars) {
if(isset($this->$className) && !$this->$className) {
require(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . $className'.php');
$this->$className = new $$className($someVars);
}
return $this->$className;
}
function DoSomething($someVars) {
$classA =& $this->LoadClass('ClassA',$someVars);
return $classA->DoSomething($someVars);
}
Code: Select all
$moduleA =& $this->GetModuleInstance('ModuleA');
$foo = $moduleA->DoSomething($bar);