zyON Posted May 22, 2014 Share Posted May 22, 2014 I'm trying (slowly) to build my first PW Module, mostly to learn how everything works internally with the API. I'm trying to attach a function with a hook to grab the event of adding a new file to a page but I'm can't seem to fire it (I'm talking about adding a new file via de admin interface). I've declared the hook in the init() fuction of the module as: $this->addHook('InputfieldFile::fileAdded', $this, 'addFile'); and my function looks like this: public function addFile($event){ $file = $event->arguments(0); $this->message("You Added a file: {$file->name}."); } The message is never displayed. I've tried with InputfieldFile::processInputDeleteFile and it works. Also I've tried with InputfieldFile::processInputDeleteFile but it doesn't seem to work either. I'm using PW 2.4.0. Any ideas? Thanks. Link to comment Share on other sites More sharing options...
apeisa Posted May 22, 2014 Share Posted May 22, 2014 I think it's because that method is probably fired in another request (file uploads are ajax). Try writing $log instead of message. 1 Link to comment Share on other sites More sharing options...
zyON Posted May 23, 2014 Author Share Posted May 23, 2014 Apeisa, Thanks, you're right. I've used: public function addFile($event){ $file = $event->arguments(0); $this->message("You Added a file: {$file->name}.", Notice::log); } and the file name is logged in the messages.txt file. It's the first time I've used the log and I had to search inside the PW files on how to use it. I guess when you wrote "Try writing $log instead of message" you are referring to the same thing but I guess there's a way using the $log variable? Link to comment Share on other sites More sharing options...
Soma Posted May 23, 2014 Share Posted May 23, 2014 Yes $log->save("mylog", "my text"); // create and write mylog.txt file if not exists 1 Link to comment Share on other sites More sharing options...
zyON Posted May 23, 2014 Author Share Posted May 23, 2014 Perfect. Thanks Soma! Link to comment Share on other sites More sharing options...
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