evanmcd Posted July 22, 2012 Share Posted July 22, 2012 Hi all, Using code provided by Ryan here, I've created a module that coverts a PageArray into JSON format. It's been super useful to me, and I'm hoping it will be for others as well PagesToJSON.module 4 Link to comment Share on other sites More sharing options...
evanmcd Posted July 22, 2012 Author Share Posted July 22, 2012 Couple things I'm looking to do to improve this module are to: add the ability to pass in the native fields you'd like in the output add an option in the Field Details section for whether or not you want the field included in JSON output Re the first one, I could use a bit of help trying to figure out how to pass options into a hooked function. I've tried adding an $options param to addHook, like this: $this->addHook('PageArray::toJSON', $this, 'pagesToJSON', $options); and calling it like this: $myPages->toJSON(array('fields' => 'id,name')); But, when I do I get this error: Method PageArray::toJSON does not exist or is not callable in this context (in /Projects/TeamScheme/teamscheme_0.5/wire/core/Wire.php line 231) If someone could point me in the right directions for adding params to hooked functions (and perhaps point to a module that implements something like I want to do wfor item #2) I would appreciate it. Thanks. Link to comment Share on other sites More sharing options...
Nico Knoll Posted July 22, 2012 Share Posted July 22, 2012 Could be really helpful for creating a public read API for a PW page sometime. Link to comment Share on other sites More sharing options...
ryan Posted July 22, 2012 Share Posted July 22, 2012 This sounds great Evan, I can't wait to check this one out. To answer your question about how to pass arguments to a hook function: $myPages->toJSON($a, $b, $c); public function toJSON(HookEvent $event) { $a = $event->arguments[0]; $b = $event->arguments[1]; $c = $event->arguments[2]; } Since you want to pass in an options array as the first argument, you would call your function like in your example, and you could retrieve the argument like this: $options = $event->arguments[0]; 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