Results 1 to 5 of 5

Thread: Calling module A in module B

  1. #1

    Default Calling module A in module B

    Is there a way to use module A inside module B's compile method?

    Code:
    module A extends Module
    module B extends ModuleXYZ
    Let a me explain, what I am looking for is a way to (import/render/call a function - what ever you might call this) module A's functionality inside module B's compile method. Depending on results of module A's inside Module B's compile method, i want to carry out further steps in module B.

    And I saw this post:
    viewtopic.php?f=9&t=1712
    also I read this blog
    http://blog.qzminski.com/2010/06/using- ... er-module/
    But i can't solve my problem :-(

    Issues are so:
    1 . Inside moduleB's compile function if i use :
    Code:
    $sqlRes =  $this->Database->prepare("SELECT * FROM tl_moduleA")->execute();
    $objModule = new ModuleA($sqlRes);
    $objModule->compile();
    Throws error - Creating default object from empty value in ... on line xyz
    line xyz has $this->Template->moduleA = $someResult;

    2.
    I can't use
    Code:
    $this->Import('moduleA');
    $result = $this->moduleA->methodA();
    because of following errors
    Argument 1 passed to Module::__construct() must be an instance of Database_Result, Now the only option is moduleA to extend Frontend. Which in turn throws an error call to undefined method moduleA::generate(). Well I can put an empty generate funtion but in whole it breaks the moduleA standalone functionality.

    3.
    class ModuleA extends ModuleParent
    {
    // ...
    }

    class ModuleB extends ModuleParent
    {
    // ...
    }

    This i can't do because ModuleA and ModuleB 2 totally different animal. Can someone show me a way to do it. Thanks lot
    OM MANI PEME HUNG! how many has to die for freedom and dignity. Save this world

  2. #2
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Calling module A in module B

    Normally what you then do is to build an Abstract Module (example 3) which is shared by both modules and both can then call the functions of the parent. Ways to see how this is built is to look at the ModuleNews which is the parent module of ModuleNewsList AND ModuleNewsReader.

    Both modules can do their own thing, but then the functions that are shared can be called in the parent.

    Alternatively if it's just the OUTPUT you're interested in, then just use the function that the inserttag calls as well:

    Code:
    protected function getFrontendModule($intId, $strColumn='main')
    use it like this:
    Code:
    $mymodule = $this->getFrontendModule(21);

  3. #3

    Default Re: Calling module A in module B

    Thanks for replying thyon.
    I can't create an Abstract as both modules already extends some parent Abstract Class. And I am also not much interested in output, as for this to work then I need to have an instance of moduleA some where.
    OM MANI PEME HUNG! how many has to die for freedom and dignity. Save this world

  4. #4
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Calling module A in module B

    Well look in Controller.php, as there you can see how the module was instantiated for the function I mentioned. That way you can copy the code, and leave the parse() part out, but you'll still be able to use the functions.

    Normally in OOP, you should rather have a HOOK and then use the HOOK in that module instead. I think some more experienced programmers like tru, leo or andreas can also comment here...

  5. #5

    Default Re: Calling module A in module B

    Well thanks again, I think for the time being I'll go with my 1st way and suppress php errors.
    OM MANI PEME HUNG! how many has to die for freedom and dignity. Save this world

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •