pwFoo Posted January 3, 2016 Posted January 3, 2016 Hi, after sone time playing without hooks I tried to hook the WireHttp method send() with the latest devns (send is now public and hookable!), but it doesn't work. What's wrong with this call inside a module? $this->addHookAfter('WireHttp::send', $this, 'hookCheckAuth'); Inside the "hookCheckAuth" I tried to echo, exit() / die() or modifiy $event->return. Works if I call the method direct, but nothing happens if I call the WireHttp send() method...? Tried it also from a template and it works with the following code: wire()->addHookAfter('WireHttp::send', function($event) { die("TEST"); }); Same code modified to use it inside a module doesn't work: $this->addHookAfter('WireHttp::send', function($event) { die("TEST"); }); $this->wire()->addHookAfter('WireHttp::send', function($event) { die("TEST"); }); wire()->addHookAfter('WireHttp::send', function($event) { die("TEST"); }); I'll reinstall PW to have a clean new install... But maybe I missed something... *UPDATE* Also tested without success: $wire->addHookAfter('WireHttp::send', function($event) { die("TEST"); });
teppo Posted January 4, 2016 Posted January 4, 2016 The problem is very likely something not visible in your post above. Testing with the setup below, I had no issues getting this to work under latest version of the devns branch: <?php # /site/modules/TestHook.module class TestHook extends WireData implements Module { public static function getModuleInfo() { return array('autoload' => true); } public function init() { $this->addHookAfter('WireHttp::send', $this, 'hookCheckAuth'); } public function hookCheckAuth(HookEvent $event) { die("dying"); } } <?php # /site/templates/basic-page.php $http = new \ProcessWire\WireHttp; $http->send('/'); 3
pwFoo Posted January 4, 2016 Author Posted January 4, 2016 Strange... reinstalled. Created a simple test module and it works fine.. Haven't found the mistake, but seems to be caused by my code Thanks for help with a test, Teppo!!!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now