Hooks & Listeners
  • Could someone explain to me how the hooks and listeners system works? There does not seem to be any working examples of it within the source code right now.
  • The aliases and page module both listen for hooks that are called, IIRC there are many others as well. Basically, a hook is called from within a library (or else where, but it is normally a core library) and with given arguments. A module can then listen for this hook call, and can do something with the provided arguments and return a response. Depending on what the library does, it can take that response from all the listeners and merge that in with some other code.

    Hooks are normally in the form of: bootstrap_loaded, view_output (taking the Aliases listeners file as an example here), and then the method that will be called is 'hookBootstrapLoaded' (basically converted to camel case).
  • Ok, I have everything working except for a few little kinks:

    * How can I extract the current controller title from within the listener?
    * Is there any internal Zulu method that can give me the current URL?
    * I'm getting a spew of PHP error messages unrelated to my module, the most persistent of which is:

    ( ! ) Warning: DOMDocument::load() [domdocument.load]: ID article-1 already defined in /home/lucas/Programming/tangocms-trunk/tmp/rss/article-latest.xml, line: 29 in /home/lucas/Programming/tangocms-trunk/application/libraries/Rss.php on line 64
    Call Stack
    # Time Memory Function Location
    1 0.0003 141448 {main}( ) ../index.php:0
    2 0.0194 2340376 require( '/home/lucas/Programming/tangocms-trunk/application/zula/bootstrap.php' ) ../index.php:102
    3 0.0748 5249240 Controller->dispatch( ) ../bootstrap.php:113
    4 0.0748 5249240 Hooks::notifyAll( ) ../Controller.php:196
    5 0.0749 5249240 call_user_func_array ( ) ../Hooks.php:127
    6 0.0749 5249240 Rss_hooks->hookCntrlrPreDispatch( ) ../Hooks.php:0
    7 0.0788 5589344 Rss->__construct( ) ../listeners.php:195
    8 0.0789 5589344 DOMDocument->load( ) ../Rss.php:64
  • For the controller title, it would depend on which hook you are listening for, what is the name of the hook you're using? Current URL can be got via:

    $this->_router->getCurrentUrl();

    However, from the module you're working on I assume you're after the full URL (ie, including http://)? I'm just about to add a new method to the routers so that data is possible. Weird about the PHP errors, I'll try and see what is causing it =)
  • Thanks for the help with the URL, I think I can do a temporary workaround until the new _router function is done.

    I need to get the title of whatever controller is being currently displayed in the main content area to use a as a title for the submission to the different news sites.

    I dont know why im getting that error, I've had it since I've installed tango /trunk.

    Thanks for the help Alex, I'll have the module done for tonight.
  • As of /trunk r2260 Router_Base::getCurrentUrl() will now return the full URL (so including http:// and the hostname), and it's old behaviour is now in Router_Base::getRequestPath(). So $this->_router->getCurrentUrl() is now what you need =).

    The title depends on the hook you're using, since if it is a hook before the controller has loaded - you wont be able to get it. What is the name of the hook you're using, I assume view_output_bottom?
  • Yes it is currently using controller output bottom... I can't think of a case where anything else would be needed.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion